code
stringlengths
3
1.05M
repo_name
stringlengths
4
116
path
stringlengths
4
991
language
stringclasses
9 values
license
stringclasses
15 values
size
int32
3
1.05M
/* Copyright (C) 2014-2015 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see <http://www.gnu.org/licenses/>. */ using System; using System.IO; using System.Linq; using dndbg.Engine; using dnlib.PE; using dnSpy.MVVM.Dialogs; namespace dnSpy.Debugger.Modules { sealed class PEFilesSaver : IProgressTask { sealed class ModuleInfo { public readonly IntPtr ProcessHandle; public readonly ulong Address; public readonly uint Size; public readonly string Filename; public bool MemoryLayout; public ModuleInfo(IntPtr handle, ulong addr, uint size, string filename, bool memoryLayout) { this.ProcessHandle = handle; this.Address = addr; this.Size = size; this.Filename = filename; this.MemoryLayout = memoryLayout; } } readonly ModuleInfo[] infos; public PEFilesSaver(Tuple<DnModule, string>[] files) { this.infos = new ModuleInfo[files.Length]; for (int i = 0; i < files.Length; i++) { var module = files[i].Item1; this.infos[i] = new ModuleInfo(module.Process.CorProcess.Handle, module.Address, module.Size, files[i].Item2, !module.IsInMemory); maxProgress += 2; } } bool IProgressTask.IsIndeterminate { get { return false; } } double IProgressTask.ProgressMinimum { get { return 0; } } double IProgressTask.ProgressMaximum { get { return maxProgress; } } readonly uint maxProgress; uint currentProgress; IProgress progress; unsafe void IProgressTask.Execute(IProgress progress) { this.progress = progress; if (infos.Length == 0) return; uint maxSize = infos.Max(a => a.Size); var buf = new byte[maxSize]; byte[] buf2 = null; foreach (var info in infos) { progress.ThrowIfCancellationRequested(); progress.SetDescription(Path.GetFileName(info.Filename)); ProcessMemoryUtils.ReadMemory(info.ProcessHandle, info.Address, buf, 0, (int)info.Size); progress.ThrowIfCancellationRequested(); currentProgress++; progress.SetTotalProgress(currentProgress); byte[] data = buf; int dataSize = (int)info.Size; if (info.MemoryLayout) { if (buf2 == null) buf2 = new byte[buf.Length]; data = buf2; WritePEFile(buf, buf2, dataSize, out dataSize); } var file = File.Create(info.Filename); try { file.Write(data, 0, dataSize); currentProgress++; progress.SetTotalProgress(currentProgress); } catch { file.Dispose(); try { File.Delete(info.Filename); } catch { } throw; } finally { file.Dispose(); } } } // Very simple, will probably fail if various fields have been overwritten with invalid values void WritePEFile(byte[] raw, byte[] dst, int rawSize, out int finalSize) { progress.ThrowIfCancellationRequested(); for (int i = 0; i < rawSize; i++) dst[i] = 0; try { var peImage = new PEImage(raw, ImageLayout.Memory, true); int offset = 0; Array.Copy(raw, 0, dst, 0, (int)peImage.ImageNTHeaders.OptionalHeader.SizeOfHeaders); offset += (int)peImage.ImageNTHeaders.OptionalHeader.SizeOfHeaders; foreach (var sect in peImage.ImageSectionHeaders) Array.Copy(raw, (int)sect.VirtualAddress, dst, (int)sect.PointerToRawData, (int)sect.SizeOfRawData); var lastSect = peImage.ImageSectionHeaders[peImage.ImageSectionHeaders.Count - 1]; var fa = peImage.ImageNTHeaders.OptionalHeader.FileAlignment; finalSize = (int)((lastSect.PointerToRawData + lastSect.SizeOfRawData + fa - 1) & ~(fa - 1)); } catch { finalSize = rawSize; Array.Copy(raw, dst, rawSize); } } } }
zuloloxi/dnSpy
dnSpy/Debugger/Modules/PEFilesSaver.cs
C#
gpl-3.0
4,184
package mq.xivklott.main; import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.IChatBaseComponent; import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer; import net.minecraft.server.v1_8_R3.PacketPlayOutTitle; import net.minecraft.server.v1_8_R3.PacketPlayOutTitle.EnumTitleAction; import net.minecraft.server.v1_8_R3.PlayerConnection; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; public class Title { public static void sendTitle(Player player, String title, String subTitle, int ticks) { IChatBaseComponent chatTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + title + "\"}"); IChatBaseComponent chatsubTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + subTitle + "\"}"); PacketPlayOutTitle titre = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, chatTitle); PacketPlayOutTitle soustitre = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, chatsubTitle); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(titre); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(soustitre); sendTime(player, ticks); } private static void sendTime(Player player, int ticks) { PacketPlayOutTitle p = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, null, 20, ticks, 20); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(p); } public static void sendActionBar(Player player, String message) { IChatBaseComponent actionBar = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + message + "\"}"); net.minecraft.server.v1_8_R3.PacketPlayOutChat ab = new net.minecraft.server.v1_8_R3.PacketPlayOutChat( actionBar, (byte) 2); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(ab); } }
HeadInBush/Skywars
src/main/java/mq/xivklott/main/Title.java
Java
gpl-3.0
1,945
/** * Created by levchenko on 5/12/14. */ function Style(styles) { this.styles = styles; this.applyStyles = function (object) { for(var key in this.styles) { if(this.getStyleProperty(key) === false) { object.setAttribute('style', object.getAttribute('style') + key + ':' + this.styles[key] + ';'); } else { object.style[this.getStyleProperty(key)] = this.styles[key]; } } }; this.getStyleProperty = function (cssProperty) { var jsProperty = ''; var partOfProperty = cssProperty.split('-'); if(cssProperty.charAt(0) == '-') { return false; } for(var key = 0; key<partOfProperty.length; key++) { if(key == 0) { jsProperty = partOfProperty[key]; continue; } jsProperty += partOfProperty[key].charAt(0).toUpperCase() + partOfProperty[key].substr(1, partOfProperty[key].length-1);; } return jsProperty; } } Element.prototype.css = function (options) { var style = (options instanceof Style) ? options : new Style(options); style.applyStyles(this); return style; }
XNoval/jsSolutions
base/Style.js
JavaScript
gpl-3.0
1,213
#include "windowfilter.h" #include <QDebug> namespace { double meanValue(const QVector<double> &x, int begin, int end); } WindowFilter::WindowFilter() :mBeginTime(std::numeric_limits<double>::lowest()), mEndTime(std::numeric_limits<double>::max()), mWindowWidth(1) { } int WindowFilter::windowWidth() const { return mWindowWidth; } std::tuple<QVector<double>, QVector<double> > WindowFilter::operator()(const QVector<double> &x, const QVector<double> &y) { QVector<double> retX = x; QVector<double> retY; int leftWidth = (mWindowWidth - 1) / 2; int rightWidth = mWindowWidth - leftWidth - 1; for (int i = 0; i < y.size(); ++i) { if (x[i] < mBeginTime || x[i] > mEndTime) { retY.push_back(y[i]); continue; } retY.push_back(meanValue(y, i - leftWidth, i + rightWidth + 1)); } return std::tuple<QVector<double>, QVector<double> >(retX, retY); } void WindowFilter::setWindowWidth(int width) { if (width <= 0) { qWarning() << "Invalid window width for window filter was detected"; return; } if (mWindowWidth != width) { mWindowWidth = width; } } void WindowFilter::setBeginTime(double time) { if (mBeginTime != time) { mBeginTime = time; } } void WindowFilter::setEndTime(double time) { if (mEndTime != time) { mEndTime = time; } } namespace { double meanValue(const QVector<double> &x, int begin, int end) { if (begin < 0) { begin = 0; } if (end > x.size()) { end = x.size(); } double sum = 0; for (int i = begin; i < end; ++i) sum += x[i]; return sum / (end - begin); } }
seleznevae/JaG
src/dataconverter/windowfilter.cpp
C++
gpl-3.0
1,691
var db = require('../db'); var User = db.model('User', { username: { type: String, required: true }, email: { type: String, required: true }, password: { type: String, required: true, select: false }, created: { type: Date, default: Date.now }, color: { type: String }, active: { type: Boolean, default: true, select: false }, scores: [], resetToken: { type: String }, resetTokenValid: { type: Date } }); module.exports = User;
MICSTI/magellan
models/user.js
JavaScript
gpl-3.0
617
<?php session_start(); $usuario=$_POST['usuario']; $recordar=$_POST['recordarme']; $retorno; if( is_numeric($usuario) && ($usuario>999999) && ($usuario<100000000) ) { if($recordar=="true") { setcookie("registro",$usuario, time()+36000 , '/'); }else { setcookie("registro",$usuario, time()-36000 , '/'); } $_SESSION['registrado']=$usuario; $retorno=" ingreso"; }else { $retorno= "No-esta"; } echo $retorno; ?>
Nicolas90/PrimerParcial
php/validarUsuario.php
PHP
gpl-3.0
438
/* * Copyright (c) Martin Kinkelin * * See the "License.txt" file in the root directory for infos * about permitted and prohibited uses of this code. */ #include <algorithm> #include <iostream> #include <locale> #include "Worker.h" #include "StringUtils.h" #include "WinRing0.h" using std::cerr; using std::endl; using std::min; using std::max; using std::string; using std::tolower; using std::vector; static void SplitPair(string& left, string& right, const string& str, char delimiter) { const size_t i = str.find(delimiter); left = str.substr(0, i); if (i == string::npos) right.clear(); else right = str.substr(i + 1); } bool Worker::ParseParams(int argc, const char* argv[]) { const Info& info = *_info; PStateInfo psi; psi.Multi = psi.VID = psi.NBVID = -1; psi.NBPState = -1; NBPStateInfo nbpsi; nbpsi.Multi = 1.0; nbpsi.VID = -1; for (int i = 0; i < info.NumPStates; i++) { _pStates.push_back(psi); _pStates.back().Index = i; } for (int i = 0; i < info.NumNBPStates; i++) { _nbPStates.push_back(nbpsi); _nbPStates.back().Index = i; } for (int i = 1; i < argc; i++) { const string param(argv[i]); string key, value; SplitPair(key, value, param, '='); if (value.empty()) { if (param.length() >= 2 && tolower(param[0]) == 'p') { const int index = atoi(param.c_str() + 1); if (index >= 0 && index < info.NumPStates) { _pState = index; continue; } } } else { if (key.length() >= 2 && tolower(key[0]) == 'p') { const int index = atoi(key.c_str() + 1); if (index >= 0 && index < info.NumPStates) { string multi, vid; SplitPair(multi, vid, value, '@'); if (!multi.empty()) _pStates[index].Multi = info.multiScaleFactor * atof(multi.c_str()); if (!vid.empty()) _pStates[index].VID = info.EncodeVID(atof(vid.c_str())); continue; } } if (key.length() >= 5 && _strnicmp(key.c_str(), "NB_P", 4) == 0) { const int index = atoi(key.c_str() + 4); if (index >= 0 && index < info.NumNBPStates) { string multi, vid; SplitPair(multi, vid, value, '@'); if (!multi.empty()) _nbPStates[index].Multi = atof(multi.c_str()); if (!vid.empty()) _nbPStates[index].VID = info.EncodeVID(atof(vid.c_str())); continue; } } if (_stricmp(key.c_str(), "NB_low") == 0) { const int index = atoi(value.c_str()); int j = 0; for (; j < min(index, info.NumPStates); j++) _pStates[j].NBPState = 0; for (; j < info.NumPStates; j++) _pStates[j].NBPState = 1; continue; } if (_stricmp(key.c_str(), "Turbo") == 0) { const int flag = atoi(value.c_str()); if (flag == 0 || flag == 1) { _turbo = flag; continue; } } if( _stricmp( key.c_str(), "BoostEnAllCores" ) == 0 ) { const int flag = atoi( value.c_str() ); if( flag == 0 || flag == 1 ) { _boostEnAllCores = flag; continue; } } if( _stricmp( key.c_str(), "IgnoreBoostThresh" ) == 0 ) { const int flag = atoi( value.c_str() ); if( flag == 0 || flag == 1 ) { _ignoreBoostThresh = flag; continue; } } if (_stricmp(key.c_str(), "APM") == 0) { const int flag = atoi(value.c_str()); if (flag == 0 || flag == 1) { _apm = flag; continue; } } if (_stricmp(key.c_str(), "NbPsi0Vid") == 0) { if (!value.empty()) _NbPsi0Vid_VID = info.EncodeVID(atof(value.c_str())); continue; } } cerr << "ERROR: invalid parameter " << param.c_str() << endl; return false; } return true; } static bool ContainsChanges(const PStateInfo& info) { return (info.Multi >= 0 || info.VID >= 0 || info.NBVID >= 0 || info.NBPState >= 0); } static bool ContainsChanges(const NBPStateInfo& info) { return (info.Multi >= 0 || info.VID >= 0); } static void SwitchTo(int logicalCPUIndex) { const HANDLE hThread = GetCurrentThread(); SetThreadAffinityMask(hThread, (DWORD_PTR)1 << logicalCPUIndex); } void Worker::ApplyChanges() { const Info& info = *_info; if (info.Family == 0x15) { for (int i = 0; i < _nbPStates.size(); i++) { const NBPStateInfo& nbpsi = _nbPStates[i]; if (ContainsChanges(nbpsi)) info.WriteNBPState(nbpsi); } } else if (info.Family == 0x10 && (_nbPStates[0].VID >= 0 || _nbPStates[1].VID >= 0)) { for (int i = 0; i < _pStates.size(); i++) { PStateInfo& psi = _pStates[i]; const int nbPState = (psi.NBPState >= 0 ? psi.NBPState : info.ReadPState(i).NBPState); const NBPStateInfo& nbpsi = _nbPStates[nbPState]; if (nbpsi.VID >= 0) psi.NBVID = nbpsi.VID; } } if (_turbo >= 0 && info.IsBoostSupported) info.SetBoostSource(_turbo == 1); if( _boostEnAllCores >= 0 && info.BoostEnAllCores != -1 ) info.SetBoostEnAllCores( _boostEnAllCores ); if( _ignoreBoostThresh >= 0 && info.IgnoreBoostThresh != -1 ) info.SetIgnoreBoostThresh( _ignoreBoostThresh ); if (_apm >= 0 && info.Family == 0x15) info.SetAPM(_apm == 1); if (_NbPsi0Vid_VID >= 0 && info.Family == 0x15) info.WriteNbPsi0Vid(_NbPsi0Vid_VID); SYSTEM_INFO sysInfo; GetSystemInfo(&sysInfo); const int numLogicalCPUs = sysInfo.dwNumberOfProcessors; // switch to the highest thread priority (we do not want to get interrupted often) const HANDLE hProcess = GetCurrentProcess(); const HANDLE hThread = GetCurrentThread(); SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS); SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); // perform one iteration in each logical core for (int j = 0; j < numLogicalCPUs; j++) { SwitchTo(j); for (int i = 0; i < _pStates.size(); i++) { const PStateInfo& psi = _pStates[i]; if (ContainsChanges(psi)) info.WritePState(psi); } if (_turbo >= 0 && info.IsBoostSupported) info.SetCPBDis(_turbo == 1); } for (int j = 0; j < numLogicalCPUs; j++) { SwitchTo(j); const int currentPState = info.GetCurrentPState(); const int newPState = (_pState >= 0 ? _pState : currentPState); if (newPState != currentPState) info.SetCurrentPState(newPState); else { if (ContainsChanges(_pStates[currentPState])) { const int tempPState = (currentPState == info.NumPStates - 1 ? 0 : info.NumPStates - 1); info.SetCurrentPState(tempPState); Sleep(1); info.SetCurrentPState(currentPState); } } } SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL); SetPriorityClass(hProcess, NORMAL_PRIORITY_CLASS); }
MWisBest/AmdMsrTweaker
Worker.cpp
C++
gpl-3.0
6,793
//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============ // // Purpose: // // $NoKeywords: $ //============================================================================= #include "cbase.h" #include "c_order_assist.h" IMPLEMENT_CLIENTCLASS_DT( C_OrderAssist, DT_OrderAssist, COrderAssist ) END_RECV_TABLE() void C_OrderAssist::GetDescription( char *pDest, int bufferSize ) { char targetDesc[512]; GetTargetDescription( targetDesc, sizeof( targetDesc ) ); Q_snprintf( pDest, bufferSize, "Assist %s", targetDesc ); }
RaisingTheDerp/raisingthebar
root/cl_dll/tf2_hud/c_order_assist.cpp
C++
gpl-3.0
550
/* * ____ DAPHNE COPYRIGHT NOTICE ____ * * Copyright (C) 2005 Mark Broadhead * * This file is part of DAPHNE, a laserdisc arcade game emulator * * DAPHNE is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * DAPHNE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include <string.h> // for memset #include <stdio.h> // for sprintf (we shouldn't use sprintf anymore) #include "timetrav.h" #include "../ldp-out/ldp.h" #include "../io/conout.h" #include "../sound/sound.h" #include "../video/palette.h" #include "../video/video.h" // Time Traveler timetrav::timetrav() { m_shortgamename = "timetrav"; memset(m_cpumem, 0, cpu::MEM_SIZE); struct cpu::def cpu; memset(&cpu, 0, sizeof(struct cpu::def)); cpu.type = cpu::type::I88; cpu.hz = TIMETRAV_CPU_HZ; cpu.irq_period[0] = 0; cpu.irq_period[1] = 0; cpu.nmi_period = (1000.0 / 59.94); cpu.initial_pc = 0xFFFF0; cpu.must_copy_context = false; cpu.mem = m_cpumem; cpu::add(&cpu); // add this cpu to the list (it will be our only one) m_disc_fps = 29.97; // m_game_type = GAME_TIMETRAV; m_game_uses_video_overlay = true; m_video_overlay_width = 320; // default values we start with for video // overlay m_video_overlay_height = 240; m_palette_color_count = 256; m_video_overlay_count = 1; m_overlay_size_is_dynamic = true; // this game does dynamically change its // overlay size static struct rom_def g_timetrav_roms[] = {{"TT061891.BIN", NULL, &m_cpumem[0xc0000], 0x40000, 0x00000000}, {NULL}}; m_rom_list = g_timetrav_roms; } void timetrav::do_nmi() {} Uint8 timetrav::cpu_mem_read(Uint32 addr) { char s[80]; Uint8 result = m_cpumem[addr]; // Scratch ram if (addr < 0x10000) { } // ROM else if (addr >= 0xc0000) { } else { sprintf(s, "Unmapped read from %x", addr); printline(s); } return (result); } void timetrav::cpu_mem_write(Uint32 addr, Uint8 value) { char s[80]; m_cpumem[addr] = value; // Scratch ram if (addr < 0x10000) { } // ROM else if (addr >= 0xc0000) { sprintf(s, "Write to rom at %x with %x!", addr, value); printline(s); } else { sprintf(s, "Unmapped write to %x with %x", addr, value); printline(s); } } void timetrav::port_write(Uint16 port, Uint8 value) { char s[80]; //static char display_string[9] = {0}; switch (port) { case 0x1180: case 0x1181: case 0x1182: case 0x1183: case 0x1184: case 0x1185: case 0x1186: case 0x1187: m_video_overlay_needs_update = true; //display_string[port & 0x07] = value; //draw_string(display_string, 0, 0, get_active_video_overlay()); blit(); break; default: sprintf(s, "Unmapped write to port %x, value %x", port, value); printline(s); break; } } Uint8 timetrav::port_read(Uint16 port) { char s[80]; unsigned char result = 0; sprintf(s, "Unmapped read from port %x", port); printline(s); return (result); } // used to set dip switch values bool timetrav::set_bank(unsigned char which_bank, unsigned char value) { bool result = true; if (which_bank == 0) { } else { printline("ERROR: Bank specified is out of range!"); result = false; } return result; } void timetrav::input_disable(Uint8 move) {} void timetrav::input_enable(Uint8 move) {} void timetrav::palette_calculate() { SDL_Color temp_color; // fill color palette with schlop because we only use colors 0 and 0xFF for // now for (int i = 0; i < 256; i++) { temp_color.r = (unsigned char)i; temp_color.g = (unsigned char)i; temp_color.b = (unsigned char)i; palette::set_color(i, temp_color); } }
btolab/hypseus
src/game/timetrav.cpp
C++
gpl-3.0
4,667
<?php session_start(); if ($_SESSION['image_is_logged_in'] == 'true' ) { $user = $_SESSION['user']; $pactiu=$_POST['actiu']; $pgrup=$_POST['grup']; $ptipus=$_POST['tipus']; include 'config/configuracio.php'; ?> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" > <link rel="stylesheet" type="text/css" href="coope.css" /> <title>llistat families ::: la coope</title> </head> <body> <div class="pagina" style="margin-top: 10px;"> <div class="contenidor_1" style="border: 1px solid orange;"> <p class='path'> ><a href='admint.php'>administració</a> >><a href='families.php'>llistat famílies</a> </p> <p class="h1" style="background: orange; text-align: left; padding-left: 20px;"> Llistat famílies </p> <table width="80%" align="center" style="padding: 10px 0px;"> <form action="families.php" method="post" name="fam" id="fam"> <tr> <td width="33%" align="center" class="form">Actiu/Baixa</td> <td width="33%" align="center" class="form">Grup</td> <td width="33%" align="center" class="form">Comissió</td> </tr> <tr> <td align="center"> <SELECT name="actiu" id="actiu" size="1" maxlength="5" onChange="this.form.submit()"> <?php if ($pactiu=='actiu') {$checked1='selected';$checked2="";} if ($pactiu=='baixa') {$checked2='selected';$checked1="";} ?> <option value="">Tots</option> <option value="actiu" <?php echo $checked1; ?>>Actiu</option> <option value="baixa" <?php echo $checked2; ?>>Baixa</option> </select> </td> <td align="center"> <SELECT name="grup" id="grup" size="1" maxlength="30" onChange="this.form.submit()"> <option value="">Tots</option> <?php $select3= "SELECT nom FROM grups ORDER BY nom"; $query3=mysql_query($select3); if (!$query3) {die('Invalid query3: ' . mysql_error());} while (list($sgrup)=mysql_fetch_row($query3)) { if ($pgrup==$sgrup){echo '<option value="'.$sgrup.'" selected>'.$sgrup.'</option>';} else {echo '<option value="'.$sgrup.'">'.$sgrup.'</option>';} } ?> </select> </td> <td align="center"> <SELECT name="tipus" id="tipus" size="1" maxlength="30" onChange="this.form.submit()"> <option value="">Tots</option> <?php if ($ptipus=='user') {$checked3='selected';$checked4="";$checked5="";$checked6="";$checked7="";$checked8="";} elseif ($ptipus=='admin') {$checked3='';$checked4="selected";$checked5="";$checked6="";$checked7="";$checked8="";} elseif ($ptipus=='eco') {$checked3='';$checked4="";$checked5="selected";$checked6="";$checked7="";$checked8="";} elseif ($ptipus=='prov') {$checked3='';$checked4="";$checked5="";$checked6="selected";$checked7="";$checked8="";} elseif ($ptipus=='cist') {$checked3='';$checked4="";$checked5="";$checked6="";$checked7="selected";$checked8="";} elseif ($ptipus=='super') {$checked3='';$checked4="";$checked5="";$checked6="";$checked7="";$checked8="selected";} echo' <option value="user" '.$checked3.'>user</option> <option value="admin" '.$checked4.'>admin</option> <option value="eco" '.$checked5.'>eco</option> <option value="prov" '.$checked6.'>prov</option> <option value="cist" '.$checked7.'>cist</option> <option value="super" '.$checked8.'>super</option>'; ?> </select> </td> </form> </tr></table> <div class="contenidor_fac" style="border: 1px solid orange; max-height: 350px; overflow: scroll; overflow-x: hidden; margin-bottom: 20px; padding-bottom: 20px;"> <?php if ($pactiu!="" AND $pgrup=="" AND $ptipus=="") {$where="WHERE tipus2='".$pactiu."'"; $title="Famílies en ".$pactiu;} elseif ($pactiu!="" AND $pgrup!="" AND $ptipus=="") {$where="WHERE tipus2='".$pactiu."' AND dia='".$pgrup."'"; $title="Famílies en ".$pactiu." del grup ".$pgrup;} elseif ($pactiu!="" AND $pgrup!="" AND $ptipus!="") {$where="WHERE tipus2='".$pactiu."' AND dia='".$pgrup."' AND tipus='".$ptipus."'"; $title="Famílies en ".$pactiu." del grup ".$pgrup." i de la comissió ".$ptipus;} elseif ($pactiu!="" AND $pgrup=="" AND $ptipus!="") {$where="WHERE tipus2='".$pactiu."' AND tipus='".$ptipus."'"; $title="Famílies en ".$pactiu." de la comissió ".$ptipus;} elseif ($pactiu=="" AND $pgrup=="" AND $ptipus!="") {$where="WHERE tipus='".$ptipus."'"; $title="Famílies de la comissió ".$ptipus;} elseif ($pactiu=="" AND $pgrup!="" AND $ptipus!="") {$where="WHERE dia='".$pgrup."' AND tipus='".$ptipus."'"; $title="Famílies del grup ".$pgrup." i de la comissió ".$ptipus;} elseif ($pactiu=="" AND $pgrup!="" AND $ptipus=="") {$where="WHERE dia='".$pgrup."'"; $title="Famílies del grup ".$pgrup;} elseif ($pactiu=="" AND $pgrup=="" AND $ptipus=="") {$where=""; $title="Totes les famílies";} print ('<p class="h1" style="background: orange; font-size:14px; text-align: left; height: 20px; padding-left: 20px;"> '.$title.' </p>'); print('<table width="100%" align="center" cellspading="5" cellspacing="5" > <tr class="cos_majus"> <td align="center" width="20%">nom</td> <td align="center" width="30%">components</td> <td align="center" width="15%">telefon</td> <td align="center" width="35%">email</td> </tr>'); $taula = "SELECT nom,components,tel1,email1 FROM usuaris ".$where." ORDER BY nom"; $result = mysql_query($taula); if (!$result) {die('Invalid query: ' . mysql_error());} while (list($nom,$components,$tel1,$email1)=mysql_fetch_row($result)) { echo "<tr class='cos'> <td align='center'><a href='vis_user.php?id=".$nom."'>".$nom." </a></td> <td align='center'>".$components."</td> <td align='center'>".$tel1."</td> <td align='center'>".$email1."</td> </tr>"; } echo "</table></div></div>"; ?> <p class="cos2" style="clear: both; text-align: center;"> Per veure la fitxa completa d'una família clicka sobre el seu nom </p> </div> </body> </html> <?php include 'config/disconect.php'; } else { header("Location: index.php"); } ?>
cst777/30pnx_aplicoop
families.php
PHP
gpl-3.0
5,746
=begin Copyright (C) 2016 Witesy Contributors This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. =end FactoryGirl.define do factory :order do order_number "1" shipping_mode "ups" payment_term "30 days" order_date "2013-12-30" ship_by "2014-12-30" shipping_address { FactoryGirl.create(:address)} billing_address { FactoryGirl.create(:address)} end end
sempliva/Witesy
spec/factories/order.rb
Ruby
gpl-3.0
947
<?php /** * @file * Contains \Drupal\content_translation\Access\ContentTranslationOverviewAccess. */ namespace Drupal\content_translation\Access; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Routing\Access\AccessInterface; use Drupal\Core\Session\AccountInterface; use Symfony\Component\Routing\Route; use Symfony\Component\HttpFoundation\Request; /** * Access check for entity translation overview. */ class ContentTranslationOverviewAccess implements AccessInterface { /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityManagerInterface */ protected $entityManager; /** * Constructs a ContentTranslationOverviewAccess object. * * @param \Drupal\Core\Entity\EntityManagerInterface $manager * The entity type manager. */ public function __construct(EntityManagerInterface $manager) { $this->entityManager = $manager; } /** * {@inheritdoc} */ public function access(Route $route, Request $request, AccountInterface $account) { $entity_type = $request->attributes->get('_entity_type'); if ($entity = $request->attributes->get($entity_type)) { // Get entity base info. $bundle = $entity->bundle(); // Get entity access callback. $definition = $this->entityManager->getDefinition($entity_type); $translation = $definition->get('translation'); $access_callback = $translation['content_translation']['access_callback']; if (call_user_func($access_callback, $entity)) { return static::ALLOW; } // Check per entity permission. $permission = "translate {$entity_type}"; if ($definition->getPermissionGranularity() == 'bundle') { $permission = "translate {$bundle} {$entity_type}"; } if ($account->hasPermission($permission)) { return static::ALLOW; } } return static::DENY; } }
Ignigena/bethel-dashboard
core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationOverviewAccess.php
PHP
gpl-3.0
1,896
package org.baeldung.boot.domain; public abstract class AbstractEntity { long id; public AbstractEntity(long id){ this.id = id; } }
Niky4000/UsefulUtils
projects/tutorials-master/tutorials-master/spring-boot-ops/src/main/java/org/baeldung/boot/domain/AbstractEntity.java
Java
gpl-3.0
159
package org.drugis.addis.subProblems.repository.impl; import org.drugis.addis.exception.ResourceDoesNotExistException; import org.drugis.addis.subProblems.SubProblem; import org.drugis.addis.subProblems.repository.SubProblemRepository; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.TypedQuery; import java.util.Collection; /** * Created by joris on 8-5-17. */ @Repository public class SubProblemRepositoryImpl implements SubProblemRepository { @Qualifier("emAddisCore") @PersistenceContext(unitName = "addisCore") private EntityManager em; @Override public SubProblem create(Integer workspaceId, String definition, String title) { SubProblem newSubProblem = new SubProblem(workspaceId, definition, title); em.persist(newSubProblem); return newSubProblem; } @Override public Collection<SubProblem> queryByProject(Integer projectId) { TypedQuery<SubProblem> query = em.createQuery( "SELECT DISTINCT sp FROM SubProblem sp\n" + " WHERE sp.workspaceId in(\n " + " SELECT id FROM AbstractAnalysis where projectid = :projectId\n" + " )", SubProblem.class); query.setParameter("projectId", projectId); return query.getResultList(); } @Override public Collection<SubProblem> queryByProjectAndAnalysis(Integer projectId, Integer workspaceId) { TypedQuery<SubProblem> query = em.createQuery( "SELECT DISTINCT sp FROM SubProblem sp\n" + " WHERE sp.workspaceId = :workspaceId \n" + " AND sp.workspaceId in(\n " + " SELECT id FROM AbstractAnalysis where id = :workspaceId and projectid = :projectId\n" + " )", SubProblem.class); query.setParameter("workspaceId", workspaceId); query.setParameter("projectId", projectId); return query.getResultList(); } @Override public SubProblem get(Integer subProblemId) throws ResourceDoesNotExistException { SubProblem subProblem = em.find(SubProblem.class, subProblemId); if (subProblem == null) { throw new ResourceDoesNotExistException(); } return subProblem; } @Override public void update(Integer analysisId, Integer subProblemId, String definition, String title) throws ResourceDoesNotExistException { SubProblem subProblem = get(subProblemId); if (definition != null) { subProblem.setDefinition(definition); } if (title != null) { subProblem.setTitle(title); } em.merge(subProblem); } }
drugis/addis-core
src/main/java/org/drugis/addis/subProblems/repository/impl/SubProblemRepositoryImpl.java
Java
gpl-3.0
2,713
/** * Copyright (C) 2007-2011, Jens Lehmann * * This file is part of DL-Learner. * * DL-Learner is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * DL-Learner is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.dllearner.kb.extraction; import java.util.ArrayList; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; import org.apache.log4j.Logger; import org.dllearner.kb.aquisitors.RDFBlankNode; import org.dllearner.kb.aquisitors.TupleAquisitor; import org.dllearner.kb.manipulator.Manipulator; import org.dllearner.utilities.datastructures.RDFNodeTuple; import org.dllearner.utilities.owl.OWLVocabulary; import org.semanticweb.owlapi.model.OWLAnnotation; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLClassExpression; import org.semanticweb.owlapi.model.OWLDataFactory; /** * Is a node in the graph, that is a class. * * @author Sebastian Hellmann */ public class ClassNode extends Node { private static Logger logger = Logger .getLogger(ClassNode.class); List<ObjectPropertyNode> classProperties = new ArrayList<ObjectPropertyNode>(); List<DatatypePropertyNode> datatypeProperties = new ArrayList<DatatypePropertyNode>(); List<BlankNode> blankNodes = new ArrayList<BlankNode>(); public ClassNode(String uri) { super(uri); } // expands all directly connected nodes @Override public List<Node> expand(TupleAquisitor tupelAquisitor, Manipulator manipulator) { SortedSet<RDFNodeTuple> newTuples = tupelAquisitor.getTupelForResource(this.uri); // see manipulator newTuples = manipulator.manipulate(this, newTuples); List<Node> newNodes = new ArrayList<Node>(); Node tmp; for (RDFNodeTuple tuple : newTuples) { if((tmp = processTuple(tuple,tupelAquisitor.isDissolveBlankNodes()))!= null) { newNodes.add(tmp); } } return newNodes; } private Node processTuple( RDFNodeTuple tuple, boolean dissolveBlankNodes) { try { String property = tuple.a.toString(); if(tuple.b.isLiteral()) { datatypeProperties.add(new DatatypePropertyNode(tuple.a.toString(), this, new LiteralNode(tuple.b) )); return null; }else if(tuple.b.isAnon()){ if(dissolveBlankNodes){ RDFBlankNode n = (RDFBlankNode) tuple.b; BlankNode tmp = new BlankNode( n, tuple.a.toString()); //add it to the graph blankNodes.add(tmp); //return tmp; return tmp; }else{ //do nothing return null; } // substitute rdf:type with owl:subclassof }else if (property.equals(OWLVocabulary.RDF_TYPE) || OWLVocabulary.isStringSubClassVocab(property)) { ClassNode tmp = new ClassNode(tuple.b.toString()); classProperties.add(new ObjectPropertyNode( OWLVocabulary.RDFS_SUBCLASS_OF, this, tmp)); return tmp; } else { // further expansion stops here ClassNode tmp = new ClassNode(tuple.b.toString()); classProperties.add(new ObjectPropertyNode(tuple.a.toString(), this, tmp)); return tmp; //is missing on purpose } } catch (Exception e) { logger.warn("Problem with: " + this + " in tuple " + tuple); e.printStackTrace(); } return null; } // gets the types for properties recursively @Override public List<BlankNode> expandProperties(TupleAquisitor tupelAquisitor, Manipulator manipulator, boolean dissolveBlankNodes) { return new ArrayList<BlankNode>(); } /* * (non-Javadoc) * * @see org.dllearner.kb.sparql.datastructure.Node#toNTriple() */ @Override public SortedSet<String> toNTriple() { SortedSet<String> returnSet = new TreeSet<String>(); String subject = getNTripleForm(); returnSet.add(subject+"<" + OWLVocabulary.RDF_TYPE + "><" + OWLVocabulary.OWL_CLASS + ">."); for (ObjectPropertyNode one : classProperties) { returnSet.add(subject + one.getNTripleForm() + one.getBPart().getNTripleForm()+" ."); returnSet.addAll(one.getBPart().toNTriple()); } for (DatatypePropertyNode one : datatypeProperties) { returnSet.add(subject+ one.getNTripleForm() + one.getNTripleFormOfB() + " ."); } return returnSet; } @Override public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){ try{ OWLDataFactory factory = owlAPIOntologyCollector.getFactory(); OWLClass me =factory.getOWLClass(getIRI()); for (ObjectPropertyNode one : classProperties) { OWLClass c = factory.getOWLClass(one.getBPart().getIRI()); if(OWLVocabulary.isStringSubClassVocab(one.getURIString())){ owlAPIOntologyCollector.addAxiom(factory.getOWLSubClassOfAxiom(me, c)); }else if(one.getURIString().equals(OWLVocabulary.OWL_DISJOINT_WITH)){ owlAPIOntologyCollector.addAxiom(factory.getOWLDisjointClassesAxiom(me, c)); }else if(one.getURIString().equals(OWLVocabulary.OWL_EQUIVALENT_CLASS)){ owlAPIOntologyCollector.addAxiom(factory.getOWLEquivalentClassesAxiom(me, c)); }else if(one.getURIString().equals(OWLVocabulary.RDFS_IS_DEFINED_BY)){ logger.warn("IGNORING: "+OWLVocabulary.RDFS_IS_DEFINED_BY); continue; }else { tail(true, "in ontology conversion"+" object property is: "+one.getURIString()+" connected with: "+one.getBPart().getURIString()); continue; } one.getBPart().toOWLOntology(owlAPIOntologyCollector); } for (DatatypePropertyNode one : datatypeProperties) { //FIXME add languages // watch for tail if(one.getURIString().equals(OWLVocabulary.RDFS_COMMENT)){ OWLAnnotation annoComment = factory.getOWLAnnotation(factory.getRDFSComment(), factory.getOWLStringLiteral(one.getBPart().getLiteral().getString())); OWLAxiom ax = factory.getOWLAnnotationAssertionAxiom(me.getIRI(), annoComment); owlAPIOntologyCollector.addAxiom(ax); }else if(one.getURIString().equals(OWLVocabulary.RDFS_LABEL)) { OWLAnnotation annoLabel = factory.getOWLAnnotation(factory.getRDFSLabel(), factory.getOWLStringLiteral(one.getBPart().getLiteral().getString())); OWLAxiom ax = factory.getOWLAnnotationAssertionAxiom(me.getIRI(), annoLabel); owlAPIOntologyCollector.addAxiom(ax); }else { tail(true, "in ontology conversion: no other datatypes, but annotation is allowed for classes."+" data property is: "+one.getURIString()+" connected with: "+one.getBPart().getNTripleForm()); } } for (BlankNode bn : blankNodes) { OWLClassExpression target = bn.getAnonymousClass(owlAPIOntologyCollector); if(OWLVocabulary.isStringSubClassVocab(bn.getInBoundEdge())){ owlAPIOntologyCollector.addAxiom(factory.getOWLSubClassOfAxiom(me, target)); }else if(bn.getInBoundEdge().equals(OWLVocabulary.OWL_DISJOINT_WITH)){ owlAPIOntologyCollector.addAxiom(factory.getOWLDisjointClassesAxiom(me, target)); }else if(bn.getInBoundEdge().equals(OWLVocabulary.OWL_EQUIVALENT_CLASS)){ owlAPIOntologyCollector.addAxiom(factory.getOWLEquivalentClassesAxiom(me, target)); }else { tail( "in ontology conversion"+" bnode is: "+bn.getInBoundEdge()+"||"+ bn ); } } }catch (Exception e) { System.out.println("aaa"+getURIString()); e.printStackTrace(); } } }
daftano/dl-learner
components-core/src/main/java/org/dllearner/kb/extraction/ClassNode.java
Java
gpl-3.0
7,843
namespace Installer { partial class frmInstaller { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.SuspendLayout(); // // frmInstaller // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(506, 394); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Name = "frmInstaller"; this.Text = "Setup"; this.ResumeLayout(false); } #endregion } }
pmdcp/Installer
Installer/frmInstaller.Designer.cs
C#
gpl-3.0
1,518
using UnityEngine; using System.Collections; public class SpawnWater : MonoBehaviour { //this controlls how long after using the water power the player must wait to use it again public float interval = 3; public float veritcalOffset = .5f; private float timer; private GameObject myWaterBlast; // Use this for initialization void Start () { if (myWaterBlast == null) { myWaterBlast = Resources.Load ("Prefabs/WaterBlast") as GameObject; } this.timer = Time.time; } // Update is called once per frame void Update () { //detect user input and check time interval if (Input.GetButtonDown("WaterPower") && Time.time - timer > interval) { //update timer timer = Time.time; //spawn water blast GameObject obj = (GameObject)Instantiate(myWaterBlast); obj.transform.position = new Vector3(this.transform.position.x, this.transform.position.y + veritcalOffset, 0f); Rigidbody2D objRB = obj.GetComponent<Rigidbody2D>() as Rigidbody2D; Rigidbody2D playerRB = GetComponent<Rigidbody2D>() as Rigidbody2D; objRB.velocity = playerRB.velocity; } } }
TeamD4D-Bothell/Sprout
TeamD4D_Sprout/Assets/Scripts/Player/SpawnWater.cs
C#
gpl-3.0
1,266
<?php /************************************************************************ * This file is part of EspoCRM. * * EspoCRM - Open Source CRM application. * Copyright (C) 2014-2021 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko * Website: https://www.espocrm.com * * EspoCRM is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * EspoCRM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ namespace Espo\Core\Formula\Functions; use Espo\Core\Exceptions\Error; use Espo\Core\Formula\AttributeFetcher; class AttributeType extends Base { protected $attributeFetcher; public function setAttributeFetcher(AttributeFetcher $attributeFetcher) { $this->attributeFetcher = $attributeFetcher; } public function process(\StdClass $item) { if (!property_exists($item, 'value')) { throw new Error(); } return $this->getAttributeValue($item->value); } protected function getAttributeValue($attribute) { return $this->attributeFetcher->fetch($this->getEntity(), $attribute); } }
ayman-alkom/espocrm
application/Espo/Core/Formula/Functions/AttributeType.php
PHP
gpl-3.0
2,037
<?php /** * This file contains the CSSHelper class. * * PHP version 5.3 * * LICENSE: This file is part of Nuggets-PHP. * Nuggets-PHP is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * Nuggets-PHP is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with Nuggets-PHP. If not, see <http://www.gnu.org/licenses/>. */ namespace nuggets; require_once('core/Helper/Helper.php'); /** * This class provides helper features for Cascading Style Sheets. * * @package nuggets\Helper * @category PHP * @author Rajdeep Das <das.rajdeep97@gmail.com> * @copyright Copyright 2012 Rajdeep Das * @license http://www.gnu.org/licenses/gpl.txt The GNU General Public License * @version GIT: v3.5 * @link https://github.com/dasrajdeep/nuggets-php * @since Class available since Release 1.0 */ class CSSHelper extends Helper { /** * Generates a CSS box shadow. * * @param int $x * @param int $y * @param int $blur * @param string $color * @param boolean $inset * @return string */ public static function getShadow($x,$y,$blur,$color,$inset=FALSE) { if($inset) $inset='inset'; else $inset=''; $attr=sprintf('%s %spx %spx %spx #%s',$inset,$x,$y,$blur,$color); $css='box-shadow:%s; -moz-box-shadow:%s; -webkit-box-shadow:%s;'; return sprintf($css,$attr,$attr,$attr); } /** * Generates a CSS gradient. * * @param string $start * @param string $stop * @return string */ public static function getGradient($start,$stop) { $raw_xml='<?xml version="1.0" ?> <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 1 1" preserveAspectRatio="none"> <linearGradient id="grad-ucgg-generated" gradientUnits="userSpaceOnUse" x1="0%" y1="0%" x2="0%" y2="100%"> <stop offset="0%"'.sprintf(' stop-color="#%s"',$start).' stop-opacity="1"/> <stop offset="100%"'.sprintf(' stop-color="#%s"',$stop).' stop-opacity="1"/> </linearGradient> <rect x="0" y="0" width="1" height="1" fill="url(#grad-ucgg-generated)" /> </svg>'; $enc_xml=base64_encode($raw_xml); $attr="#".$start." 0%, #".$stop." 100%"; $css=sprintf("background: #%s; background: url(data:image/svg+xml;base64,%s);",$start,$enc_xml).sprintf(" background: -moz-linear-gradient(top, %s); background: -webkit-linear-gradient(top, %s); background: -o-linear-gradient(top, %s); background: -ms-linear-gradient(top, %s); background: linear-gradient(top, %s);",$attr,$attr,$attr,$attr,$attr)." background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#".$start."), color-stop(100%,#".$stop.")); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#".$start."', endColorstr='#".$stop."',GradientType=0 );"; return $css; } /** * Generates CSS transparency. * * @param int $amount * @return string */ public static function getTransparency($amount) { $css='filter:alpha(opacity=%s); -moz-opacity:%s; -khtml-opacity:%s; opacity:%s; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=%s)";'; return sprintf($css,$amount*100,$amount,$amount,$amount,$amount*100); } } ?>
dasrajdeep/nuggets-php
core/Helper/CSSHelper.php
PHP
gpl-3.0
3,892
/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) ************************************************************************ */ /** * Contains some common methods available to all log appenders. */ qx.Class.define("qx.log.appender.Util", { statics : { /** * Converts a single log entry to HTML * * @signature function(entry) * @param entry {Map} The entry to process * @return {void} */ toHtml : function(entry) { var output = []; var item, msg, sub, list; output.push("<span class='offset'>", this.formatOffset(entry.offset, 6), "</span> "); if (entry.object) { var obj = entry.win.qx.core.ObjectRegistry.fromHashCode(entry.object); if (obj) { output.push("<span class='object' title='Object instance with hash code: " + obj.$$hash + "'>", obj.classname, "[" , obj.$$hash, "]</span>: "); } } else if (entry.clazz) { output.push("<span class='object'>" + entry.clazz.classname, "</span>: "); } var items = entry.items; for (var i=0, il=items.length; i<il; i++) { item = items[i]; msg = item.text; if (msg instanceof Array) { var list = []; for (var j=0, jl=msg.length; j<jl; j++) { sub = msg[j]; if (typeof sub === "string") { list.push("<span>" + this.escapeHTML(sub) + "</span>"); } else if (sub.key) { list.push("<span class='type-key'>" + sub.key + "</span>:<span class='type-" + sub.type + "'>" + this.escapeHTML(sub.text) + "</span>"); } else { list.push("<span class='type-" + sub.type + "'>" + this.escapeHTML(sub.text) + "</span>"); } } output.push("<span class='type-" + item.type + "'>"); if (item.type === "map") { output.push("{", list.join(", "), "}"); } else { output.push("[", list.join(", "), "]"); } output.push("</span>"); } else { output.push("<span class='type-" + item.type + "'>" + this.escapeHTML(msg) + "</span> "); } } var wrapper = document.createElement("DIV"); wrapper.innerHTML = output.join(""); wrapper.className = "level-" + entry.level; return wrapper; }, /** * Formats a numeric time offset to 6 characters. * * @param offset {Integer} Current offset value * @param length {Integer?6} Refine the length * @return {String} Padded string */ formatOffset : function(offset, length) { var str = offset.toString(); var diff = (length||6) - str.length; var pad = ""; for (var i=0; i<diff; i++) { pad += "0"; } return pad+str; }, /** * Escapes the HTML in the given value * * @param value {String} value to escape * @return {String} escaped value */ escapeHTML : function(value) { return String(value).replace(/[<>&"']/g, this.__escapeHTMLReplace); }, /** * Internal replacement helper for HTML escape. * * @param ch {String} Single item to replace. * @return {String} Replaced item */ __escapeHTMLReplace : function(ch) { var map = { "<" : "&lt;", ">" : "&gt;", "&" : "&amp;", "'" : "&#39;", '"' : "&quot;" }; return map[ch] || "?"; }, /** * Converts a single log entry to plain text * * @param entry {Map} The entry to process * @return {String} the formatted log entry */ toText : function(entry) { return this.toTextArray(entry).join(" "); }, /** * Converts a single log entry to an array of plain text * * @param entry {Map} The entry to process * @return {Array} Argument list ready message array. */ toTextArray : function(entry) { var output = []; output.push(this.formatOffset(entry.offset, 6)); if (entry.object) { var obj = entry.win.qx.core.ObjectRegistry.fromHashCode(entry.object); if (obj) { output.push(obj.classname + "[" + obj.$$hash + "]:"); } } else if (entry.clazz) { output.push(entry.clazz.classname + ":"); } var items = entry.items; var item, msg; for (var i=0, il=items.length; i<il; i++) { item = items[i]; msg = item.text; if (item.trace && item.trace.length > 0) { if (typeof(this.FORMAT_STACK) == "function") { qx.log.Logger.deprecatedConstantWarning(qx.log.appender.Util, "FORMAT_STACK", "Use qx.dev.StackTrace.FORMAT_STACKTRACE instead"); msg += "\n" + this.FORMAT_STACK(item.trace); } else { msg += "\n" + item.trace; } } if (msg instanceof Array) { var list = []; for (var j=0, jl=msg.length; j<jl; j++) { list.push(msg[j].text); } if (item.type === "map") { output.push("{", list.join(", "), "}"); } else { output.push("[", list.join(", "), "]"); } } else { output.push(msg); } } return output; } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) ************************************************************************ */ /* ************************************************************************ #require(qx.log.appender.Util) #require(qx.bom.client.Html) -- defer calls Logger.register which calls Native.process which needs "html.console" implementation ************************************************************************ */ /** * Processes the incoming log entry and displays it by means of the native * logging capabilities of the client. * * Supported browsers: * * Firefox <4 using FireBug (if available). * * Firefox >=4 using the Web Console. * * WebKit browsers using the Web Inspector/Developer Tools. * * Internet Explorer 8+ using the F12 Developer Tools. * * Opera >=10.60 using either the Error Console or Dragonfly * * Currently unsupported browsers: * * Opera <10.60 */ qx.Class.define("qx.log.appender.Native", { /* ***************************************************************************** STATICS ***************************************************************************** */ statics : { /** * Processes a single log entry * * @param entry {Map} The entry to process */ process : function(entry) { if (qx.core.Environment.get("html.console")) { // Firefox 4's Web Console doesn't support "debug" var level = console[entry.level] ? entry.level : "log"; if (console[level]) { var args = qx.log.appender.Util.toText(entry); console[level](args); } } } }, /* ***************************************************************************** DEFER ***************************************************************************** */ defer : function(statics) { qx.log.Logger.register(statics); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) ************************************************************************ */ /* ************************************************************************ #require(qx.event.handler.Window) #require(qx.event.handler.Keyboard) ************************************************************************ */ /** * Feature-rich console appender for the qooxdoo logging system. * * Creates a small inline element which is placed in the top-right corner * of the window. Prints all messages with a nice color highlighting. * * * Allows user command inputs. * * Command history enabled by default (Keyboard up/down arrows). * * Lazy creation on first open. * * Clearing the console using a button. * * Display of offset (time after loading) of each message * * Supports keyboard shortcuts F7 or Ctrl+D to toggle the visibility */ qx.Class.define("qx.log.appender.Console", { statics : { /* --------------------------------------------------------------------------- INITIALIZATION AND SHUTDOWN --------------------------------------------------------------------------- */ /** * Initializes the console, building HTML and pushing last * log messages to the output window. * * @return {void} */ init : function() { // Build style sheet content var style = [ '.qxconsole{z-index:10000;width:600px;height:300px;top:0px;right:0px;position:absolute;border-left:1px solid black;color:black;border-bottom:1px solid black;color:black;font-family:Consolas,Monaco,monospace;font-size:11px;line-height:1.2;}', '.qxconsole .control{background:#cdcdcd;border-bottom:1px solid black;padding:4px 8px;}', '.qxconsole .control a{text-decoration:none;color:black;}', '.qxconsole .messages{background:white;height:100%;width:100%;overflow:auto;}', '.qxconsole .messages div{padding:0px 4px;}', '.qxconsole .messages .user-command{color:blue}', '.qxconsole .messages .user-result{background:white}', '.qxconsole .messages .user-error{background:#FFE2D5}', '.qxconsole .messages .level-debug{background:white}', '.qxconsole .messages .level-info{background:#DEEDFA}', '.qxconsole .messages .level-warn{background:#FFF7D5}', '.qxconsole .messages .level-error{background:#FFE2D5}', '.qxconsole .messages .level-user{background:#E3EFE9}', '.qxconsole .messages .type-string{color:black;font-weight:normal;}', '.qxconsole .messages .type-number{color:#155791;font-weight:normal;}', '.qxconsole .messages .type-boolean{color:#15BC91;font-weight:normal;}', '.qxconsole .messages .type-array{color:#CC3E8A;font-weight:bold;}', '.qxconsole .messages .type-map{color:#CC3E8A;font-weight:bold;}', '.qxconsole .messages .type-key{color:#565656;font-style:italic}', '.qxconsole .messages .type-class{color:#5F3E8A;font-weight:bold}', '.qxconsole .messages .type-instance{color:#565656;font-weight:bold}', '.qxconsole .messages .type-stringify{color:#565656;font-weight:bold}', '.qxconsole .command{background:white;padding:2px 4px;border-top:1px solid black;}', '.qxconsole .command input{width:100%;border:0 none;font-family:Consolas,Monaco,monospace;font-size:11px;line-height:1.2;}', '.qxconsole .command input:focus{outline:none;}' ]; // Include stylesheet qx.bom.Stylesheet.createElement(style.join("")); // Build markup var markup = [ '<div class="qxconsole">', '<div class="control"><a href="javascript:qx.log.appender.Console.clear()">Clear</a> | <a href="javascript:qx.log.appender.Console.toggle()">Hide</a></div>', '<div class="messages">', '</div>', '<div class="command">', '<input type="text"/>', '</div>', '</div>' ]; // Insert HTML to access DOM node var wrapper = document.createElement("DIV"); wrapper.innerHTML = markup.join(""); var main = wrapper.firstChild; document.body.appendChild(wrapper.firstChild); // Make important DOM nodes available this.__main = main; this.__log = main.childNodes[1]; this.__cmd = main.childNodes[2].firstChild; // Correct height of messages frame this.__onResize(); // Finally register to log engine qx.log.Logger.register(this); // Register to object manager qx.core.ObjectRegistry.register(this); }, /** * Used by the object registry to dispose this instance e.g. remove listeners etc. * * @return {void} */ dispose : function() { qx.event.Registration.removeListener(document.documentElement, "keypress", this.__onKeyPress, this); qx.log.Logger.unregister(this); }, /* --------------------------------------------------------------------------- INSERT & CLEAR --------------------------------------------------------------------------- */ /** * Clears the current console output. * * @return {void} */ clear : function() { // Remove all messages this.__log.innerHTML = ""; }, /** * Processes a single log entry * * @signature function(entry) * @param entry {Map} The entry to process * @return {void} */ process : function(entry) { // Append new content this.__log.appendChild(qx.log.appender.Util.toHtml(entry)); // Scroll down this.__scrollDown(); }, /** * Automatically scroll down to the last line */ __scrollDown : function() { this.__log.scrollTop = this.__log.scrollHeight; }, /* --------------------------------------------------------------------------- VISIBILITY TOGGLING --------------------------------------------------------------------------- */ /** {Boolean} Flag to store last visibility status */ __visible : true, /** * Toggles the visibility of the console between visible and hidden. * * @return {void} */ toggle : function() { if (!this.__main) { this.init(); } else if (this.__main.style.display == "none") { this.show(); } else { this.__main.style.display = "none"; } }, /** * Shows the console. * * @return {void} */ show : function() { if (!this.__main) { this.init(); } else { this.__main.style.display = "block"; this.__log.scrollTop = this.__log.scrollHeight; } }, /* --------------------------------------------------------------------------- COMMAND LINE SUPPORT --------------------------------------------------------------------------- */ /** {Array} List of all previous commands. */ __history : [], /** * Executes the currently given command * * @return {void} */ execute : function() { var value = this.__cmd.value; if (value == "") { return; } if (value == "clear") { return this.clear(); } var command = document.createElement("div"); command.innerHTML = qx.log.appender.Util.escapeHTML(">>> " + value); command.className = "user-command"; this.__history.push(value); this.__lastCommand = this.__history.length; this.__log.appendChild(command); this.__scrollDown(); try { var ret = window.eval(value); } catch (ex) { qx.log.Logger.error(ex); } if (ret !== undefined) { qx.log.Logger.debug(ret); } }, /* --------------------------------------------------------------------------- EVENT LISTENERS --------------------------------------------------------------------------- */ /** * Event handler for resize listener * * @param e {Event} Event object * @return {void} */ __onResize : function(e) { this.__log.style.height = (this.__main.clientHeight - this.__main.firstChild.offsetHeight - this.__main.lastChild.offsetHeight) + "px"; }, /** * Event handler for keydown listener * * @param e {Event} Event object * @return {void} */ __onKeyPress : function(e) { var iden = e.getKeyIdentifier(); // Console toggling if ((iden == "F7") || (iden == "D" && e.isCtrlPressed())) { this.toggle(); e.preventDefault(); } // Not yet created if (!this.__main) { return; } // Active element not in console if (!qx.dom.Hierarchy.contains(this.__main, e.getTarget())) { return; } // Command execution if (iden == "Enter" && this.__cmd.value != "") { this.execute(); this.__cmd.value = ""; } // History managment if (iden == "Up" || iden == "Down") { this.__lastCommand += iden == "Up" ? -1 : 1; this.__lastCommand = Math.min(Math.max(0, this.__lastCommand), this.__history.length); var entry = this.__history[this.__lastCommand]; this.__cmd.value = entry || ""; this.__cmd.select(); } } }, /* ***************************************************************************** DEFER ***************************************************************************** */ defer : function(statics) { qx.event.Registration.addListener(document.documentElement, "keypress", statics.__onKeyPress, statics); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Mixin used for the bubbling events. If you want to use this in your own model * classes, be sure that every property will call the * {@link #_applyEventPropagation} function on every change. */ qx.Mixin.define("qx.data.marshal.MEventBubbling", { events : { /** * The change event which will be fired on every change in the model no * matter what property changes. This event bubbles so the root model will * fire a change event on every change of its children properties too. * * Note that properties are required to call * {@link #_applyEventPropagation} on apply for changes to be tracked as * desired. It is already taken care of that properties created with the * {@link qx.data.marshal.Json} marshaler call this method. * * The data will contain a map with the following three keys * <li>value: The new value of the property</li> * <li>old: The old value of the property.</li> * <li>name: The name of the property changed including its parent * properties separated by dots.</li> * <li>item: The item which has the changed property.</li> * Due to that, the <code>getOldData</code> method will always return null * because the old data is contained in the map. */ "changeBubble": "qx.event.type.Data" }, members : { /** * Apply function for every property created with the * {@link qx.data.marshal.Json} marshaler. It fires and * {@link #changeBubble} event on every change. It also adds the chaining * listener if possible which is necessary for the bubbling of the events. * * @param value {var} The new value of the property. * @param old {var} The old value of the property. * @param name {String} The name of the changed property. */ _applyEventPropagation : function(value, old, name) { this.fireDataEvent("changeBubble", { value: value, name: name, old: old, item: this }); this._registerEventChaining(value, old, name); }, /** * Registers for the given parameters the changeBubble listener, if * possible. It also removes the old listener, if an old item with * a changeBubble event is given. * * @param value {var} The new value of the property. * @param old {var} The old value of the property. * @param name {String} The name of the changed property. */ _registerEventChaining : function(value, old, name) { // if the child supports chaining if ((value instanceof qx.core.Object) && qx.Class.hasMixin(value.constructor, qx.data.marshal.MEventBubbling) ) { // create the listener var listener = qx.lang.Function.bind( this.__changePropertyListener, this, name ); // add the listener var id = value.addListener("changeBubble", listener, this); var listeners = value.getUserData("idBubble-" + this.$$hash); if (listeners == null) { listeners = []; value.setUserData("idBubble-" + this.$$hash, listeners); } listeners.push(id); } // if an old value is given, remove the old listener if possible if (old != null && old.getUserData && old.getUserData("idBubble-" + this.$$hash) != null) { var listeners = old.getUserData("idBubble-" + this.$$hash); for (var i = 0; i < listeners.length; i++) { old.removeListenerById(listeners[i]); } old.setUserData("idBubble-" + this.$$hash, null); } }, /** * Listener responsible for formating the name and firing the change event * for the changed property. * * @param name {String} The name of the former properties. * @param e {qx.event.type.Data} The date event fired by the property * change. */ __changePropertyListener : function(name, e) { var data = e.getData(); var value = data.value; var old = data.old; // if the target is an array if (qx.Class.hasInterface(e.getTarget().constructor, qx.data.IListData)) { if (data.name.indexOf) { var dotIndex = data.name.indexOf(".") != -1 ? data.name.indexOf(".") : data.name.length; var bracketIndex = data.name.indexOf("[") != -1 ? data.name.indexOf("[") : data.name.length; // braktes in the first spot is ok [BUG #5985] if (bracketIndex == 0) { var newName = name + data.name; } else if (dotIndex < bracketIndex) { var index = data.name.substring(0, dotIndex); var rest = data.name.substring(dotIndex + 1, data.name.length); if (rest[0] != "[") { rest = "." + rest; } var newName = name + "[" + index + "]" + rest; } else if (bracketIndex < dotIndex) { var index = data.name.substring(0, bracketIndex); var rest = data.name.substring(bracketIndex, data.name.length); var newName = name + "[" + index + "]" + rest; } else { var newName = name + "[" + data.name + "]"; } } else { var newName = name + "[" + data.name + "]"; } // if the target is not an array } else { // special case for array as first element of the chain [BUG #5985] if (parseInt(name) == name && name !== "") { name = "[" + name + "]"; } var newName = name + "." + data.name; } this.fireDataEvent( "changeBubble", { value: value, name: newName, old: old, item: data.item || e.getTarget() } ); } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * The data array is a special array used in the data binding context of * qooxdoo. It does not extend the native array of JavaScript but its a wrapper * for it. All the native methods are included in the implementation and it * also fires events if the content or the length of the array changes in * any way. Also the <code>.length</code> property is available on the array. */ qx.Class.define("qx.data.Array", { extend : qx.core.Object, include : qx.data.marshal.MEventBubbling, implement : [qx.data.IListData], /** * Creates a new instance of an array. * * @param param {var} The parameter can be some types.<br/> * Without a parameter a new blank array will be created.<br/> * If there is more than one parameter is given, the parameter will be * added directly to the new array.<br/> * If the parameter is a number, a new Array with the given length will be * created.<br/> * If the parameter is a JavaScript array, a new array containing the given * elements will be created. */ construct : function(param) { this.base(arguments); // if no argument is given if (param == undefined) { this.__array = []; // check for elements (create the array) } else if (arguments.length > 1) { // create an empty array and go through every argument and push it this.__array = []; for (var i = 0; i < arguments.length; i++) { this.__array.push(arguments[i]); } // check for a number (length) } else if (typeof param == "number") { this.__array = new Array(param); // check for an array itself } else if (param instanceof Array) { this.__array = qx.lang.Array.clone(param); // error case } else { this.__array = []; this.dispose(); throw new Error("Type of the parameter not supported!"); } // propagate changes for (var i=0; i<this.__array.length; i++) { this._applyEventPropagation(this.__array[i], null, i); } // update the length at startup this.__updateLength(); // work against the console printout of the array if (qx.core.Environment.get("qx.debug")) { this[0] = "Please use 'toArray()' to see the content."; } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * Flag to set the dispose behavior of the array. If the property is set to * <code>true</code>, the array will dispose its content on dispose, too. */ autoDisposeItems : { check : "Boolean", init : false } }, /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** * The change event which will be fired if there is a change in the array. * The data contains a map with three key value pairs: * <li>start: The start index of the change.</li> * <li>end: The end index of the change.</li> * <li>type: The type of the change as a String. This can be 'add', * 'remove' or 'order'</li> * <li>items: The items which has been changed (as a JavaScript array).</li> */ "change" : "qx.event.type.Data", /** * The changeLength event will be fired every time the length of the * array changes. */ "changeLength": "qx.event.type.Data" }, members : { // private members __array : null, /** * Concatenates the current and the given array into a new one. * * @param array {Array} The javaScript array which should be concatenated * to the current array. * * @return {qx.data.Array} A new array containing the values of both former * arrays. */ concat: function(array) { if (array) { var newArray = this.__array.concat(array); } else { var newArray = this.__array.concat(); } return new qx.data.Array(newArray); }, /** * Returns the array as a string using the given connector string to * connect the values. * * @param connector {String} the string which should be used to past in * between of the array values. * * @return {String} The array as a string. */ join: function(connector) { return this.__array.join(connector); }, /** * Removes and returns the last element of the array. * An change event will be fired. * * @return {var} The last element of the array. */ pop: function() { var item = this.__array.pop(); this.__updateLength(); // remove the possible added event listener this._registerEventChaining(null, item, this.length - 1); // fire change bubble event this.fireDataEvent("changeBubble", { value: [], name: this.length + "", old: [item], item: this }); this.fireDataEvent("change", { start: this.length - 1, end: this.length - 1, type: "remove", items: [item] }, null ); return item; }, /** * Adds an element at the end of the array. * * @param varargs {var} Multiple elements. Every element will be added to * the end of the array. An change event will be fired. * * @return {Number} The new length of the array. */ push: function(varargs) { for (var i = 0; i < arguments.length; i++) { this.__array.push(arguments[i]); this.__updateLength(); // apply to every pushed item an event listener for the bubbling this._registerEventChaining(arguments[i], null, this.length - 1); // fire change bubbles event this.fireDataEvent("changeBubble", { value: [arguments[i]], name: (this.length - 1) + "", old: [], item: this }); // fire change event this.fireDataEvent("change", { start: this.length - 1, end: this.length - 1, type: "add", items: [arguments[i]] }, null ); } return this.length; }, /** * Reverses the order of the array. An change event will be fired. */ reverse: function() { // ignore on empty arrays if (this.length == 0) { return; } var oldArray = this.__array.concat(); this.__array.reverse(); this.fireDataEvent("change", {start: 0, end: this.length - 1, type: "order", items: null}, null ); // fire change bubbles event this.fireDataEvent("changeBubble", { value: this.__array, name: "0-" + (this.__array.length - 1), old: oldArray, item: this }); }, /** * Removes the first element of the array and returns it. An change event * will be fired. * * @return {var} the former first element. */ shift: function() { // ignore on empty arrays if (this.length == 0) { return; } var item = this.__array.shift(); this.__updateLength(); // remove the possible added event listener this._registerEventChaining(null, item, this.length -1); // fire change bubbles event this.fireDataEvent("changeBubble", { value: [], name: "0", old: [item], item: this }); // fire change event this.fireDataEvent("change", { start: 0, end: this.length -1, type: "remove", items: [item] }, null ); return item; }, /** * Returns a new array based on the range specified by the parameters. * * @param from {Number} The start index. * @param to {Number?null} The end index. If omitted, slice extracts to the * end of the array. * * @return {qx.data.Array} A new array containing the given range of values. */ slice: function(from, to) { return new qx.data.Array(this.__array.slice(from, to)); }, /** * Method to remove and add new elements to the array. For every remove or * add an event will be fired. * * @param startIndex {Integer} The index where the splice should start * @param amount {Integer} Defines number of elements which will be removed * at the given position. * @param varargs {var} All following parameters will be added at the given * position to the array. * @return {qx.data.Array} An data array containing the removed elements. * Keep in to dispose this one, even if you don't use it! */ splice: function(startIndex, amount, varargs) { // store the old length var oldLength = this.__array.length; // invoke the slice on the array var returnArray = this.__array.splice.apply(this.__array, arguments); // fire a change event for the length if (this.__array.length != oldLength) { this.__updateLength(); } // fire an event for the change var removed = amount > 0; var added = arguments.length > 2; var items = null; if (removed || added) { if (this.__array.length > oldLength) { var type = "add"; items = qx.lang.Array.fromArguments(arguments, 2); } else if (this.__array.length < oldLength) { var type = "remove"; items = returnArray; } else { var type = "order"; } this.fireDataEvent("change", { start: startIndex, end: this.length - 1, type: type, items: items }, null ); } // add listeners for (var i = 2; i < arguments.length; i++) { this._registerEventChaining(arguments[i], null, startIndex + i); } // fire the changeBubble event var value = []; for (var i=2; i < arguments.length; i++) { value[i-2] = arguments[i]; }; var endIndex = (startIndex + Math.max(arguments.length - 3 , amount - 1)); var name = startIndex == endIndex ? endIndex : startIndex + "-" + endIndex; this.fireDataEvent("changeBubble", { value: value, name: name + "", old: returnArray, item: this }); // remove the listeners for (var i = 0; i < returnArray.length; i++) { this._registerEventChaining(null, returnArray[i], i); } return (new qx.data.Array(returnArray)); }, /** * Sorts the array. If a function is given, this will be used to * compare the items. <code>changeBubble</code> event will only be fired, * if sorting result differs from original array. * * @param func {Function} A compare function comparing two parameters and * should return a number. */ sort: function(func) { // ignore if the array is empty if (this.length == 0) { return; } var oldArray = this.__array.concat(); this.__array.sort.apply(this.__array, arguments); // prevent changeBubble event if nothing has been changed if (qx.lang.Array.equals(this.__array, oldArray) === true){ return; } this.fireDataEvent("change", {start: 0, end: this.length - 1, type: "order", items: null}, null ); // fire change bubbles event this.fireDataEvent("changeBubble", { value: this.__array, name: "0-" + (this.length - 1), old: oldArray, item: this }); }, /** * Adds the given items to the beginning of the array. For every element, * a change event will be fired. * * @param varargs {var} As many elements as you want to add to the beginning. */ unshift: function(varargs) { for (var i = arguments.length - 1; i >= 0; i--) { this.__array.unshift(arguments[i]) this.__updateLength(); // apply to every pushed item an event listener for the bubbling this._registerEventChaining(arguments[i], null, 0); // fire change bubbles event this.fireDataEvent("changeBubble", { value: [this.__array[0]], name: "0", old: [this.__array[1]], item: this }); // fire change event this.fireDataEvent("change", { start: 0, end: this.length - 1, type: "add", items: [arguments[i]] }, null ); } return this.length; }, /** * Returns the list data as native array. Beware of the fact that the * internal representation will be returnd and any manipulation of that * can cause a misbehavior of the array. This method should only be used for * debugging purposes. * * @return {Array} The native array. */ toArray: function() { return this.__array; }, /** * Replacement function for the getting of the array value. * array[0] should be array.getItem(0). * * @param index {Number} The index requested of the array element. * * @return {var} The element at the given index. */ getItem: function(index) { return this.__array[index]; }, /** * Replacement function for the setting of an array value. * array[0] = "a" should be array.setItem(0, "a"). * A change event will be fired if the value changes. Setting the same * value again will not lead to a change event. * * @param index {Number} The index of the array element. * @param item {var} The new item to set. */ setItem: function(index, item) { var oldItem = this.__array[index]; // ignore settings of already set items [BUG #4106] if (oldItem === item) { return; } this.__array[index] = item; // set an event listener for the bubbling this._registerEventChaining(item, oldItem, index); // only update the length if its changed if (this.length != this.__array.length) { this.__updateLength(); } // fire change bubbles event this.fireDataEvent("changeBubble", { value: [item], name: index + "", old: [oldItem], item: this }); // fire change event this.fireDataEvent("change", { start: index, end: index, type: "add", items: [item] }, null ); }, /** * This method returns the current length stored under .length on each * array. * * @return {Number} The current length of the array. */ getLength: function() { return this.length; }, /** * Returns the index of the item in the array. If the item is not in the * array, -1 will be returned. * * @param item {var} The item of which the index should be returned. * @return {Number} The Index of the given item. */ indexOf: function(item) { return this.__array.indexOf(item); }, /** * Returns the toString of the original Array * @return {String} The array as a string. */ toString: function() { if (this.__array != null) { return this.__array.toString(); } return ""; }, /* --------------------------------------------------------------------------- IMPLEMENTATION OF THE QX.LANG.ARRAY METHODS --------------------------------------------------------------------------- */ /** * Check if the given item is in the current array. * * @param item {var} The item which is possibly in the array. * @return {boolean} true, if the array contains the given item. */ contains: function(item) { return this.__array.indexOf(item) !== -1; }, /** * Return a copy of the given arr * * @return {qx.data.Array} copy of this */ copy : function() { return this.concat(); }, /** * Insert an element at a given position. * * @param index {Integer} Position where to insert the item. * @param item {var} The element to insert. */ insertAt : function(index, item) { this.splice(index, 0, item).dispose(); }, /** * Insert an item into the array before a given item. * * @param before {var} Insert item before this object. * @param item {var} The item to be inserted. */ insertBefore : function(before, item) { var index = this.indexOf(before); if (index == -1) { this.push(item); } else { this.splice(index, 0, item).dispose(); } }, /** * Insert an element into the array after a given item. * * @param after {var} Insert item after this object. * @param item {var} Object to be inserted. */ insertAfter : function(after, item) { var index = this.indexOf(after); if (index == -1 || index == (this.length - 1)) { this.push(item); } else { this.splice(index + 1, 0, item).dispose(); } }, /** * Remove an element from the array at the given index. * * @param index {Integer} Index of the item to be removed. * @return {var} The removed item. */ removeAt : function(index) { var returnArray = this.splice(index, 1); var item = returnArray.getItem(0); returnArray.dispose(); return item; }, /** * Remove all elements from the array. * * @return {Array} A native array containing the removed elements. */ removeAll : function() { // remove all possible added event listeners for (var i = 0; i < this.__array.length; i++) { this._registerEventChaining(null, this.__array[i], i); } // ignore if array is empty if (this.getLength() == 0) { return; } // store the old data var oldLength = this.getLength(); var items = this.__array.concat(); // change the length this.__array.length = 0; this.__updateLength(); // fire change bubbles event this.fireDataEvent("changeBubble", { value: [], name: "0-" + (oldLength - 1), old: items, item: this }); // fire the change event this.fireDataEvent("change", { start: 0, end: oldLength - 1, type: "remove", items: items }, null ); return items; }, /** * Append the items of the given array. * * @param array {Array|qx.data.IListData} The items of this array will * be appended. * @throws An exception if the second argument is not an array. */ append : function(array) { // qooxdoo array support if (array instanceof qx.data.Array) { array = array.toArray(); } // this check is important because opera throws an uncatchable error if // apply is called without an array as argument. if (qx.core.Environment.get("qx.debug")) { qx.core.Assert.assertArray(array, "The parameter must be an array."); } Array.prototype.push.apply(this.__array, array); // add a listener to the new items for (var i = 0; i < array.length; i++) { this._registerEventChaining(array[i], null, this.__array.length + i); } var oldLength = this.length; this.__updateLength(); // fire change bubbles var name = oldLength == (this.length-1) ? oldLength : oldLength + "-" + (this.length-1); this.fireDataEvent("changeBubble", { value: array, name: name + "", old: [], item: this }); // fire the change event this.fireDataEvent("change", { start: oldLength, end: this.length - 1, type: "add", items: array }, null ); }, /** * Remove the given item. * * @param item {var} Item to be removed from the array. * @return {var} The removed item. */ remove : function(item) { var index = this.indexOf(item); if (index != -1) { this.splice(index, 1).dispose(); return item; } }, /** * Check whether the given array has the same content as this. * Checks only the equality of the arrays' content. * * @param array {qx.data.Array} The array to check. * @return {Boolean} Whether the two arrays are equal. */ equals : function(array) { if (this.length !== array.length) { return false; } for (var i = 0; i < this.length; i++) { if (this.getItem(i) !== array.getItem(i)) { return false; } } return true; }, /** * Returns the sum of all values in the array. Supports * numeric values only. * * @return {Number} The sum of all values. */ sum : function() { var result = 0; for (var i = 0; i < this.length; i++) { result += this.getItem(i); } return result; }, /** * Returns the highest value in the given array. * Supports numeric values only. * * @return {Number | null} The highest of all values or undefined if the * array is empty. */ max : function() { var result = this.getItem(0); for (var i = 1; i < this.length; i++) { if (this.getItem(i) > result) { result = this.getItem(i); } } return result === undefined ? null : result; }, /** * Returns the lowest value in the array. Supports * numeric values only. * * @return {Number | null} The lowest of all values or undefined * if the array is empty. */ min : function() { var result = this.getItem(0); for (var i = 1; i < this.length; i++) { if (this.getItem(i) < result) { result = this.getItem(i); } } return result === undefined ? null : result; }, /** * Invokes the given function for every item in the array. * * @param callback {Function} The function which will be call for every * item in the array. It will be invoked with three parameters: * the item, the index and the array itself. * @param context {var} The context in which the callback will be invoked. */ forEach : function(callback, context) { for (var i = 0; i < this.__array.length; i++) { callback.call(context, this.__array[i], i, this); } }, /* --------------------------------------------------------------------------- INTERNAL HELPERS --------------------------------------------------------------------------- */ /** * Internal function which updates the length property of the array. * Every time the length will be updated, a {@link #changeLength} data * event will be fired. */ __updateLength: function() { var oldLength = this.length; this.length = this.__array.length; this.fireDataEvent("changeLength", this.length, oldLength); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { for (var i = 0; i < this.__array.length; i++) { var item = this.__array[i]; this._applyEventPropagation(null, item, i); // dispose the items on auto dispose if (this.isAutoDisposeItems() && item && item instanceof qx.core.Object) { item.dispose(); } } this.__array = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's left-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A vertical box layout. * * The vertical box layout lays out widgets in a vertical column, from top * to bottom. * * *Features* * * * Minimum and maximum dimensions * * Prioritized growing/shrinking (flex) * * Margins (with vertical collapsing) * * Auto sizing (ignoring percent values) * * Percent heights (not relevant for size hint) * * Alignment (child property {@link qx.ui.core.LayoutItem#alignY} is ignored) * * Vertical spacing (collapsed with margins) * * Reversed children layout (from last to first) * * Horizontal children stretching (respecting size hints) * * *Item Properties* * * <ul> * <li><strong>flex</strong> <em>(Integer)</em>: The flexibility of a layout item determines how the container * distributes remaining empty space among its children. If items are made * flexible, they can grow or shrink accordingly. Their relative flex values * determine how the items are being resized, i.e. the larger the flex ratio * of two items, the larger the resizing of the first item compared to the * second. * * If there is only one flex item in a layout container, its actual flex * value is not relevant. To disallow items to become flexible, set the * flex value to zero. * </li> * <li><strong>height</strong> <em>(String)</em>: Allows to define a percent * height for the item. The height in percent, if specified, is used instead * of the height defined by the size hint. The minimum and maximum height still * takes care of the element's limits. It has no influence on the layout's * size hint. Percent values are mostly useful for widgets which are sized by * the outer hierarchy. * </li> * </ul> * * *Example* * * Here is a little example of how to use the grid layout. * * <pre class="javascript"> * var layout = new qx.ui.layout.VBox(); * layout.setSpacing(4); // apply spacing * * var container = new qx.ui.container.Composite(layout); * * container.add(new qx.ui.core.Widget()); * container.add(new qx.ui.core.Widget()); * container.add(new qx.ui.core.Widget()); * </pre> * * *External Documentation* * * See <a href='http://manual.qooxdoo.org/${qxversion}/pages/layout/box.html'>extended documentation</a> * and links to demos for this layout. * */ qx.Class.define("qx.ui.layout.VBox", { extend : qx.ui.layout.Abstract, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param spacing {Integer?0} The spacing between child widgets {@link #spacing}. * @param alignY {String?"top"} Vertical alignment of the whole children * block {@link #alignY}. * @param separator {Decorator} A separator to render between the items */ construct : function(spacing, alignY, separator) { this.base(arguments); if (spacing) { this.setSpacing(spacing); } if (alignY) { this.setAlignY(alignY); } if (separator) { this.setSeparator(separator); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * Vertical alignment of the whole children block. The vertical * alignment of the child is completely ignored in VBoxes ( * {@link qx.ui.core.LayoutItem#alignY}). */ alignY : { check : [ "top", "middle", "bottom" ], init : "top", apply : "_applyLayoutChange" }, /** * Horizontal alignment of each child. Can be overridden through * {@link qx.ui.core.LayoutItem#alignX}. */ alignX : { check : [ "left", "center", "right" ], init : "left", apply : "_applyLayoutChange" }, /** Vertical spacing between two children */ spacing : { check : "Integer", init : 0, apply : "_applyLayoutChange" }, /** Separator lines to use between the objects */ separator : { check : "Decorator", nullable : true, apply : "_applyLayoutChange" }, /** Whether the actual children list should be laid out in reversed order. */ reversed : { check : "Boolean", init : false, apply : "_applyReversed" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __heights : null, __flexs : null, __enableFlex : null, __children : null, /* --------------------------------------------------------------------------- HELPER METHODS --------------------------------------------------------------------------- */ // property apply _applyReversed : function() { // easiest way is to invalidate the cache this._invalidChildrenCache = true; // call normal layout change this._applyLayoutChange(); }, /** * Rebuilds caches for flex and percent layout properties */ __rebuildCache : function() { var children = this._getLayoutChildren(); var length = children.length; var enableFlex = false; var reuse = this.__heights && this.__heights.length != length && this.__flexs && this.__heights; var props; // Sparse array (keep old one if lengths has not been modified) var heights = reuse ? this.__heights : new Array(length); var flexs = reuse ? this.__flexs : new Array(length); // Reverse support if (this.getReversed()) { children = children.concat().reverse(); } // Loop through children to preparse values for (var i=0; i<length; i++) { props = children[i].getLayoutProperties(); if (props.height != null) { heights[i] = parseFloat(props.height) / 100; } if (props.flex != null) { flexs[i] = props.flex; enableFlex = true; } else { // reset (in case the index of the children changed: BUG #3131) flexs[i] = 0; } } // Store data if (!reuse) { this.__heights = heights; this.__flexs = flexs; } this.__enableFlex = enableFlex this.__children = children; // Clear invalidation marker delete this._invalidChildrenCache; }, /* --------------------------------------------------------------------------- LAYOUT INTERFACE --------------------------------------------------------------------------- */ // overridden verifyLayoutProperty : qx.core.Environment.select("qx.debug", { "true" : function(item, name, value) { this.assert(name === "flex" || name === "height", "The property '"+name+"' is not supported by the VBox layout!"); if (name =="height") { this.assertMatch(value, qx.ui.layout.Util.PERCENT_VALUE); } else { // flex this.assertNumber(value); this.assert(value >= 0); } }, "false" : null }), // overridden renderLayout : function(availWidth, availHeight) { // Rebuild flex/height caches if (this._invalidChildrenCache) { this.__rebuildCache(); } // Cache children var children = this.__children; var length = children.length; var util = qx.ui.layout.Util; // Compute gaps var spacing = this.getSpacing(); var separator = this.getSeparator(); if (separator) { var gaps = util.computeVerticalSeparatorGaps(children, spacing, separator); } else { var gaps = util.computeVerticalGaps(children, spacing, true); } // First run to cache children data and compute allocated height var i, child, height, percent; var heights = []; var allocatedHeight = gaps; for (i=0; i<length; i+=1) { percent = this.__heights[i]; height = percent != null ? Math.floor((availHeight - gaps) * percent) : children[i].getSizeHint().height; heights.push(height); allocatedHeight += height; } // Flex support (growing/shrinking) if (this.__enableFlex && allocatedHeight != availHeight) { var flexibles = {}; var flex, offset; for (i=0; i<length; i+=1) { flex = this.__flexs[i]; if (flex > 0) { hint = children[i].getSizeHint(); flexibles[i]= { min : hint.minHeight, value : heights[i], max : hint.maxHeight, flex : flex }; } } var result = util.computeFlexOffsets(flexibles, availHeight, allocatedHeight); for (i in result) { offset = result[i].offset; heights[i] += offset; allocatedHeight += offset; } } // Start with top coordinate var top = children[0].getMarginTop(); // Alignment support if (allocatedHeight < availHeight && this.getAlignY() != "top") { top = availHeight - allocatedHeight; if (this.getAlignY() === "middle") { top = Math.round(top / 2); } } // Layouting children var hint, left, width, height, marginBottom, marginLeft, marginRight; // Pre configure separators this._clearSeparators(); // Compute separator height if (separator) { var separatorInsets = qx.theme.manager.Decoration.getInstance().resolve(separator).getInsets(); var separatorHeight = separatorInsets.top + separatorInsets.bottom; } // Render children and separators for (i=0; i<length; i+=1) { child = children[i]; height = heights[i]; hint = child.getSizeHint(); marginLeft = child.getMarginLeft(); marginRight = child.getMarginRight(); // Find usable width width = Math.max(hint.minWidth, Math.min(availWidth-marginLeft-marginRight, hint.maxWidth)); // Respect horizontal alignment left = util.computeHorizontalAlignOffset(child.getAlignX()||this.getAlignX(), width, availWidth, marginLeft, marginRight); // Add collapsed margin if (i > 0) { // Whether a separator has been configured if (separator) { // add margin of last child and spacing top += marginBottom + spacing; // then render the separator at this position this._renderSeparator(separator, { top : top, left : 0, height : separatorHeight, width : availWidth }); // and finally add the size of the separator, the spacing (again) and the top margin top += separatorHeight + spacing + child.getMarginTop(); } else { // Support margin collapsing when no separator is defined top += util.collapseMargins(spacing, marginBottom, child.getMarginTop()); } } // Layout child child.renderLayout(left, top, width, height); // Add height top += height; // Remember bottom margin (for collapsing) marginBottom = child.getMarginBottom(); } }, // overridden _computeSizeHint : function() { // Rebuild flex/height caches if (this._invalidChildrenCache) { this.__rebuildCache(); } var util = qx.ui.layout.Util; var children = this.__children; // Initialize var minHeight=0, height=0, percentMinHeight=0; var minWidth=0, width=0; var child, hint, margin; // Iterate over children for (var i=0, l=children.length; i<l; i+=1) { child = children[i]; hint = child.getSizeHint(); // Sum up heights height += hint.height; // Detect if child is shrinkable or has percent height and update minHeight var flex = this.__flexs[i]; var percent = this.__heights[i]; if (flex) { minHeight += hint.minHeight; } else if (percent) { percentMinHeight = Math.max(percentMinHeight, Math.round(hint.minHeight/percent)); } else { minHeight += hint.height; } // Build horizontal margin sum margin = child.getMarginLeft() + child.getMarginRight(); // Find biggest width if ((hint.width+margin) > width) { width = hint.width + margin; } // Find biggest minWidth if ((hint.minWidth+margin) > minWidth) { minWidth = hint.minWidth + margin; } } minHeight += percentMinHeight; // Respect gaps var spacing = this.getSpacing(); var separator = this.getSeparator(); if (separator) { var gaps = util.computeVerticalSeparatorGaps(children, spacing, separator); } else { var gaps = util.computeVerticalGaps(children, spacing, true); } // Return hint return { minHeight : minHeight + gaps, height : height + gaps, minWidth : minWidth, width : width }; } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this.__heights = this.__flexs = this.__children = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * The form object is responsible for managing form items. For that, it takes * advantage of two existing qooxdoo classes. * The {@link qx.ui.form.Resetter} is used for resetting and the * {@link qx.ui.form.validation.Manager} is used for all validation purposes. * * The view code can be found in the used renderer ({@link qx.ui.form.renderer}). */ qx.Class.define("qx.ui.form.Form", { extend : qx.core.Object, construct : function() { this.base(arguments); this.__groups = []; this._buttons = []; this._buttonOptions = []; this._validationManager = new qx.ui.form.validation.Manager(); this._resetter = this._createResetter(); }, members : { __groups : null, _validationManager : null, _groupCounter : 0, _buttons : null, _buttonOptions : null, _resetter : null, /* --------------------------------------------------------------------------- ADD --------------------------------------------------------------------------- */ /** * Adds a form item to the form including its internal * {@link qx.ui.form.validation.Manager} and {@link qx.ui.form.Resetter}. * * *Hint:* The order of all add calls represent the order in the layout. * * @param item {qx.ui.form.IForm} A supported form item. * @param label {String} The string, which should be used as label. * @param validator {Function | qx.ui.form.validation.AsyncValidator ? null} * The validator which is used by the validation * {@link qx.ui.form.validation.Manager}. * @param name {String?null} The name which is used by the data binding * controller {@link qx.data.controller.Form}. * @param validatorContext {var?null} The context of the validator. * @param options {Map?null} An additional map containin custom data which * will be available in your form renderer specific to the added item. */ add : function(item, label, validator, name, validatorContext, options) { if (this.__isFirstAdd()) { this.__groups.push({ title: null, items: [], labels: [], names: [], options: [], headerOptions: {} }); } // save the given arguments this.__groups[this._groupCounter].items.push(item); this.__groups[this._groupCounter].labels.push(label); this.__groups[this._groupCounter].options.push(options); // if no name is given, use the label without not working character if (name == null) { name = label.replace( /\s+|&|-|\+|\*|\/|\||!|\.|,|:|\?|;|~|%|\{|\}|\(|\)|\[|\]|<|>|=|\^|@|\\/g, "" ); } this.__groups[this._groupCounter].names.push(name); // add the item to the validation manager this._validationManager.add(item, validator, validatorContext); // add the item to the reset manager this._resetter.add(item); }, /** * Adds a group header to the form. * * *Hint:* The order of all add calls represent the order in the layout. * * @param title {String} The title of the group header. * @param options {Map?null} A special set of custom data which will be * given to the renderer. */ addGroupHeader : function(title, options) { if (!this.__isFirstAdd()) { this._groupCounter++; } this.__groups.push({ title: title, items: [], labels: [], names: [], options: [], headerOptions: options }); }, /** * Adds a button to the form. * * *Hint:* The order of all add calls represent the order in the layout. * * @param button {qx.ui.form.Button} The button to add. * @param options {Map?null} An additional map containin custom data which * will be available in your form renderer specific to the added button. */ addButton : function(button, options) { this._buttons.push(button); this._buttonOptions.push(options || null); }, /** * Returns whether something has already been added. * * @return {Boolean} true, if nothing has been added jet. */ __isFirstAdd : function() { return this.__groups.length === 0; }, /* --------------------------------------------------------------------------- RESET SUPPORT --------------------------------------------------------------------------- */ /** * Resets the form. This means reseting all form items and the validation. */ reset : function() { this._resetter.reset(); this._validationManager.reset(); }, /** * Redefines the values used for resetting. It calls * {@link qx.ui.form.Resetter#redefine} to get that. */ redefineResetter : function() { this._resetter.redefine(); }, /* --------------------------------------------------------------------------- VALIDATION --------------------------------------------------------------------------- */ /** * Validates the form using the * {@link qx.ui.form.validation.Manager#validate} method. * * @return {Boolean | null} The validation result. */ validate : function() { return this._validationManager.validate(); }, /** * Returns the internally used validation manager. If you want to do some * enhanced validation tasks, you need to use the validation manager. * * @return {qx.ui.form.validation.Manager} The used manager. */ getValidationManager : function() { return this._validationManager; }, /* --------------------------------------------------------------------------- RENDERER SUPPORT --------------------------------------------------------------------------- */ /** * Accessor method for the renderer which returns all added items in a * array containing a map of all items: * {title: title, items: [], labels: [], names: []} * * @return {Array} An array containing all necessary data for the renderer. * @internal */ getGroups : function() { return this.__groups; }, /** * Accessor method for the renderer which returns all added buttons in an * array. * @return {Array} An array containing all added buttons. * @internal */ getButtons : function() { return this._buttons; }, /** * Accessor method for the renderer which returns all added options for * the buttons in an array. * @return {Array} An array containing all added options for the buttons. * @internal */ getButtonOptions : function() { return this._buttonOptions; }, /* --------------------------------------------------------------------------- INTERNAL --------------------------------------------------------------------------- */ /** * Returns all added items as a map. * * @return {Map} A map containing for every item an entry with its name. * * @internal */ getItems : function() { var items = {}; // go threw all groups for (var i = 0; i < this.__groups.length; i++) { var group = this.__groups[i]; // get all items for (var j = 0; j < group.names.length; j++) { var name = group.names[j]; items[name] = group.items[j]; } } return items; }, /** * Creates and returns the used resetter class. * * @return {qx.ui.form.Resetter} the resetter class. * * @internal */ _createResetter : function() { return new qx.ui.form.Resetter(); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { // holding references to widgets --> must set to null this.__groups = this._buttons = this._buttonOptions = null; this._validationManager.dispose(); this._resetter.dispose(); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * This validation manager is responsible for validation of forms. */ qx.Class.define("qx.ui.form.validation.Manager", { extend : qx.core.Object, construct : function() { this.base(arguments); // storage for all form items this.__formItems = []; // storage for all results of async validation calls this.__asyncResults = {}; // set the default required field message this.setRequiredFieldMessage(qx.locale.Manager.tr("This field is required")); }, events : { /** * Change event for the valid state. */ "changeValid" : "qx.event.type.Data", /** * Signals that the validation is done. This is not needed on synchronous * validation (validation is done right after the call) but very important * in the case an asynchronous validator will be used. */ "complete" : "qx.event.type.Event" }, properties : { /** * {Function | AsyncValidator} * The validator of the form itself. You can set a function (for * synchronous validation) or a {@link qx.ui.form.validation.AsyncValidator}. * In both cases, the function can have all added form items as first * argument and the manager as a second argument. The manager should be used * to set the {@link #invalidMessage}. * * Keep in mind that the validator is optional if you don't need the * validation in the context of the whole form. */ validator : { check : "value instanceof Function || qx.Class.isSubClassOf(value.constructor, qx.ui.form.validation.AsyncValidator)", init : null, nullable : true }, /** * The invalid message should store the message why the form validation * failed. It will be added to the array returned by * {@link #getInvalidMessages}. */ invalidMessage : { check : "String", init: "" }, /** * This message will be shown if a required field is empty and no individual * {@link qx.ui.form.MForm#requiredInvalidMessage} is given. */ requiredFieldMessage : { check : "String", init : "" }, /** * The context for the form validation. */ context : { nullable : true } }, members : { __formItems : null, __valid : null, __asyncResults : null, __syncValid : null, /** * Add a form item to the validation manager. * * The form item has to implement at least two interfaces: * <ol> * <li>The {@link qx.ui.form.IForm} Interface</li> * <li>One of the following interfaces: * <ul> * <li>{@link qx.ui.form.IBooleanForm}</li> * <li>{@link qx.ui.form.IColorForm}</li> * <li>{@link qx.ui.form.IDateForm}</li> * <li>{@link qx.ui.form.INumberForm}</li> * <li>{@link qx.ui.form.IStringForm}</li> * </ul> * </li> * </ol> * The validator can be a synchronous or asynchronous validator. In * both cases the validator can either returns a boolean or fire an * {@link qx.core.ValidationError}. For synchronous validation, a plain * JavaScript function should be used. For all asynchronous validations, * a {@link qx.ui.form.validation.AsyncValidator} is needed to wrap the * plain function. * * @param formItem {qx.ui.core.Widget} The form item to add. * @param validator {Function | qx.ui.form.validation.AsyncValidator} * The validator. * @param context {var?null} The context of the validator. */ add: function(formItem, validator, context) { // check for the form API if (!this.__supportsInvalid(formItem)) { throw new Error("Added widget not supported."); } // check for the data type if (this.__supportsSingleSelection(formItem) && !formItem.getValue) { // check for a validator if (validator != null) { throw new Error("Widgets supporting selection can only be validated " + "in the form validator"); } } var dataEntry = { item : formItem, validator : validator, valid : null, context : context }; this.__formItems.push(dataEntry); }, /** * Remove a form item from the validation manager. * * @param formItem {qx.ui.core.Widget} The form item to remove. * @return {qx.ui.core.Widget?null} The removed form item or * <code>null</code> if the item could not be found. */ remove : function(formItem) { var items = this.__formItems; for (var i = 0, len = items.length; i < len; i++) { if (formItem === items[i].item) { items.splice(i, 1); return formItem; } } return null; }, /** * Returns registered form items from the validation manager. * * @return {Array} The form items which will be validated. */ getItems : function() { var items = []; for (var i=0; i < this.__formItems.length; i++) { items.push(this.__formItems[i].item); }; return items; }, /** * Invokes the validation. If only synchronous validators are set, the * result of the whole validation is available at the end of the method * and can be returned. If an asynchronous validator is set, the result * is still unknown at the end of this method so nothing will be returned. * In both cases, a {@link #complete} event will be fired if the validation * has ended. The result of the validation can then be accessed with the * {@link #getValid} method. * * @return {Boolean | void} The validation result, if available. */ validate : function() { var valid = true; this.__syncValid = true; // collaboration of all synchronous validations var items = []; // check all validators for the added form items for (var i = 0; i < this.__formItems.length; i++) { var formItem = this.__formItems[i].item; var validator = this.__formItems[i].validator; // store the items in case of form validation items.push(formItem); // ignore all form items without a validator if (validator == null) { // check for the required property var validatorResult = this.__validateRequired(formItem); valid = valid && validatorResult; this.__syncValid = validatorResult && this.__syncValid; continue; } var validatorResult = this.__validateItem( this.__formItems[i], formItem.getValue() ); // keep that order to ensure that null is returned on async cases valid = validatorResult && valid; if (validatorResult != null) { this.__syncValid = validatorResult && this.__syncValid; } } // check the form validator (be sure to invoke it even if the form // items are already false, so keep the order!) var formValid = this.__validateForm(items); if (qx.lang.Type.isBoolean(formValid)) { this.__syncValid = formValid && this.__syncValid; } valid = formValid && valid; this.__setValid(valid); if (qx.lang.Object.isEmpty(this.__asyncResults)) { this.fireEvent("complete"); } return valid; }, /** * Checks if the form item is required. If so, the value is checked * and the result will be returned. If the form item is not required, true * will be returned. * * @param formItem {qx.ui.core.Widget} The form item to check. */ __validateRequired : function(formItem) { if (formItem.getRequired()) { // if its a widget supporting the selection if (this.__supportsSingleSelection(formItem)) { var validatorResult = !!formItem.getSelection()[0]; // otherwise, a value should be supplied } else { var validatorResult = !!formItem.getValue(); } formItem.setValid(validatorResult); var individualMessage = formItem.getRequiredInvalidMessage(); var message = individualMessage ? individualMessage : this.getRequiredFieldMessage(); formItem.setInvalidMessage(message); return validatorResult; } return true; }, /** * Validates a form item. This method handles the differences of * synchronous and asynchronous validation and returns the result of the * validation if possible (synchronous cases). If the validation is * asynchronous, null will be returned. * * @param dataEntry {Object} The map stored in {@link #add} * @param value {var} The currently set value */ __validateItem : function(dataEntry, value) { var formItem = dataEntry.item; var context = dataEntry.context; var validator = dataEntry.validator; // check for asynchronous validation if (this.__isAsyncValidator(validator)) { // used to check if all async validations are done this.__asyncResults[formItem.toHashCode()] = null; validator.validate(formItem, formItem.getValue(), this, context); return null; } var validatorResult = null; try { var validatorResult = validator.call(context || this, value, formItem); if (validatorResult === undefined) { validatorResult = true; } } catch (e) { if (e instanceof qx.core.ValidationError) { validatorResult = false; if (e.message && e.message != qx.type.BaseError.DEFAULTMESSAGE) { var invalidMessage = e.message; } else { var invalidMessage = e.getComment(); } formItem.setInvalidMessage(invalidMessage); } else { throw e; } } formItem.setValid(validatorResult); dataEntry.valid = validatorResult; return validatorResult; }, /** * Validates the form. It checks for asynchronous validation and handles * the differences to synchronous validation. If no form validator is given, * true will be returned. If a synchronous validator is given, the * validation result will be returned. In asynchronous cases, null will be * returned cause the result is not available. * * @param items {qx.ui.core.Widget[]} An array of all form items. * @return {Boolean|null} description */ __validateForm: function(items) { var formValidator = this.getValidator(); var context = this.getContext() || this; if (formValidator == null) { return true; } // reset the invalidMessage this.setInvalidMessage(""); if (this.__isAsyncValidator(formValidator)) { this.__asyncResults[this.toHashCode()] = null; formValidator.validateForm(items, this, context); return null; } try { var formValid = formValidator.call(context, items, this); if (formValid === undefined) { formValid = true; } } catch (e) { if (e instanceof qx.core.ValidationError) { formValid = false; if (e.message && e.message != qx.type.BaseError.DEFAULTMESSAGE) { var invalidMessage = e.message; } else { var invalidMessage = e.getComment(); } this.setInvalidMessage(invalidMessage); } else { throw e; } } return formValid; }, /** * Helper function which checks, if the given validator is synchronous * or asynchronous. * * @param validator {Function||qx.ui.form.validation.Asyncvalidator} * The validator to check. * @return {Boolean} True, if the given validator is asynchronous. */ __isAsyncValidator : function(validator) { var async = false; if (!qx.lang.Type.isFunction(validator)) { async = qx.Class.isSubClassOf( validator.constructor, qx.ui.form.validation.AsyncValidator ); } return async; }, /** * Returns true, if the given item implements the {@link qx.ui.form.IForm} * interface. * * @param formItem {qx.core.Object} The item to check. * @return {boolean} true, if the given item implements the * necessary interface. */ __supportsInvalid : function(formItem) { var clazz = formItem.constructor; return qx.Class.hasInterface(clazz, qx.ui.form.IForm); }, /** * Returns true, if the given item implements the * {@link qx.ui.core.ISingleSelection} interface. * * @param formItem {qx.core.Object} The item to check. * @return {boolean} true, if the given item implements the * necessary interface. */ __supportsSingleSelection : function(formItem) { var clazz = formItem.constructor; return qx.Class.hasInterface(clazz, qx.ui.core.ISingleSelection); }, /** * Internal setter for the valid member. It generates the event if * necessary and stores the new value * * @param value {Boolean|null} The new valid value of the manager. */ __setValid: function(value) { var oldValue = this.__valid; this.__valid = value; // check for the change event if (oldValue != value) { this.fireDataEvent("changeValid", value, oldValue); } }, /** * Returns the valid state of the manager. * * @return {Boolean|null} The valid state of the manager. */ getValid: function() { return this.__valid; }, /** * Returns the valid state of the manager. * * @return {Boolean|null} The valid state of the manager. */ isValid: function() { return this.getValid(); }, /** * Returns an array of all invalid messages of the invalid form items and * the form manager itself. * * @return {String[]} All invalid messages. */ getInvalidMessages: function() { var messages = []; // combine the messages of all form items for (var i = 0; i < this.__formItems.length; i++) { var formItem = this.__formItems[i].item; if (!formItem.getValid()) { messages.push(formItem.getInvalidMessage()); } } // add the forms fail message if (this.getInvalidMessage() != "") { messages.push(this.getInvalidMessage()); } return messages; }, /** * Selects invalid form items * * @return {Array} invalid form items */ getInvalidFormItems : function() { var res = []; for (var i = 0; i < this.__formItems.length; i++) { var formItem = this.__formItems[i].item; if (!formItem.getValid()) { res.push(formItem); } } return res; }, /** * Resets the validator. */ reset: function() { // reset all form items for (var i = 0; i < this.__formItems.length; i++) { var dataEntry = this.__formItems[i]; // set the field to valid dataEntry.item.setValid(true); } // set the manager to its inital valid value this.__valid = null; }, /** * Internal helper method to set the given item to valid for asynchronous * validation calls. This indirection is used to determinate if the * validation process is completed or if other asynchronous validators * are still validating. {@link #__checkValidationComplete} checks if the * validation is complete and will be called at the end of this method. * * @param formItem {qx.ui.core.Widget} The form item to set the valid state. * @param valid {Boolean} The valid state for the form item. * * @internal */ setItemValid: function(formItem, valid) { // store the result this.__asyncResults[formItem.toHashCode()] = valid; formItem.setValid(valid); this.__checkValidationComplete(); }, /** * Internal helper method to set the form manager to valid for asynchronous * validation calls. This indirection is used to determinate if the * validation process is completed or if other asynchronous validators * are still validating. {@link #__checkValidationComplete} checks if the * validation is complete and will be called at the end of this method. * * @param valid {Boolean} The valid state for the form manager. * * @internal */ setFormValid : function(valid) { this.__asyncResults[this.toHashCode()] = valid; this.__checkValidationComplete(); }, /** * Checks if all asynchronous validators have validated so the result * is final and the {@link #complete} event can be fired. If that's not * the case, nothing will happen in the method. */ __checkValidationComplete : function() { var valid = this.__syncValid; // check if all async validators are done for (var hash in this.__asyncResults) { var currentResult = this.__asyncResults[hash]; valid = currentResult && valid; // the validation is not done so just do nothing if (currentResult == null) { return; } } // set the actual valid state of the manager this.__setValid(valid); // reset the results this.__asyncResults = {}; // fire the complete event (no entry in the results with null) this.fireEvent("complete"); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this.__formItems = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * This class is responsible for validation in all asynchronous cases and * should always be used with {@link qx.ui.form.validation.Manager}. * * * It acts like a wrapper for asynchronous validation functions. These * validation function must be set in the constructor. The form manager will * invoke the validation and the validator function will be called with two * arguments: * <ul> * <li>asyncValidator: A reference to the corresponding validator.</li> * <li>value: The value of the assigned input field.</li> * </ul> * These two parameters are needed to set the validation status of the current * validator. {@link #setValid} is responsible for doing that. * * * *Warning:* Instances of this class can only be used with one input * field at a time. Multi usage is not supported! * * *Warning:* Calling {@link #setValid} synchronously does not work. If you * have an synchronous validator, please check * {@link qx.ui.form.validation.Manager#add}. If you have both cases, you have * to wrap the synchronous call in a timeout to make it asychronous. */ qx.Class.define("qx.ui.form.validation.AsyncValidator", { extend : qx.core.Object, /** * @param validator {Function} The validator function, which has to be * asynchronous. */ construct : function(validator) { this.base(arguments); // save the validator function this.__validatorFunction = validator; }, members : { __validatorFunction : null, __item : null, __manager : null, __usedForForm : null, /** * The validate function should only be called by * {@link qx.ui.form.validation.Manager}. * * It stores the given information and calls the validation function set in * the constructor. The method is used for form fields only. Validating a * form itself will be invokes with {@link #validateForm}. * * @param item {qx.ui.core.Widget} The form item which should be validated. * @param value {var} The value of the form item. * @param manager {qx.ui.form.validation.Manager} A reference to the form * manager. * @param context {var?null} The context of the validator. * * @internal */ validate: function(item, value, manager, context) { // mark as item validator this.__usedForForm = false; // store the item and the manager this.__item = item; this.__manager = manager; // invoke the user set validator function this.__validatorFunction.call(context || this, this, value); }, /** * The validateForm function should only be called by * {@link qx.ui.form.validation.Manager}. * * It stores the given information and calls the validation function set in * the constructor. The method is used for forms only. Validating a * form item will be invokes with {@link #validate}. * * @param items {qx.ui.core.Widget[]} All form items of the form manager. * @param manager {qx.ui.form.validation.Manager} A reference to the form * manager. * @param context {var?null} The context of the validator. * * @internal */ validateForm : function(items, manager, context) { this.__usedForForm = true; this.__manager = manager; this.__validatorFunction.call(context, items, this); }, /** * This method should be called within the asynchronous callback to tell the * validator the result of the validation. * * @param valid {boolean} The boolean state of the validation. * @param message {String?} The invalidMessage of the validation. */ setValid: function(valid, message) { // valid processing if (this.__usedForForm) { // message processing if (message !== undefined) { this.__manager.setInvalidMessage(message); } this.__manager.setFormValid(valid); } else { // message processing if (message !== undefined) { this.__item.setInvalidMessage(message); } this.__manager.setItemValid(this.__item, valid); } } }, /* ***************************************************************************** DESTRUCT ***************************************************************************** */ destruct : function() { this.__manager = this.__item = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Christian Hagendorn (chris_schmidt) * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Each object, which should support single selection have to * implement this interface. */ qx.Interface.define("qx.ui.core.ISingleSelection", { /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fires after the selection was modified */ "changeSelection" : "qx.event.type.Data" }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** * Returns an array of currently selected items. * * Note: The result is only a set of selected items, so the order can * differ from the sequence in which the items were added. * * @return {qx.ui.core.Widget[]} List of items. */ getSelection : function() { return true; }, /** * Replaces current selection with the given items. * * @param items {qx.ui.core.Widget[]} Items to select. * @throws an exception if the item is not a child element. */ setSelection : function(items) { return arguments.length == 1; }, /** * Clears the whole selection at once. */ resetSelection : function() { return true; }, /** * Detects whether the given item is currently selected. * * @param item {qx.ui.core.Widget} Any valid selectable item * @return {Boolean} Whether the item is selected. * @throws an exception if the item is not a child element. */ isSelected : function(item) { return arguments.length == 1; }, /** * Whether the selection is empty. * * @return {Boolean} Whether the selection is empty. */ isSelectionEmpty : function() { return true; }, /** * Returns all elements which are selectable. * * @param all {boolean} true for all selectables, false for the * selectables the user can interactively select * @return {qx.ui.core.Widget[]} The contained items. */ getSelectables: function(all) { return arguments.length == 1; } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * The resetter is responsible for managing a set of items and resetting these * items on a {@link #reset} call. It can handle all form items supplying a * value property and all widgets implementing the single selection linked list * or select box. */ qx.Class.define("qx.ui.form.Resetter", { extend : qx.core.Object, construct : function() { this.base(arguments); this.__items = []; }, members : { __items : null, /** * Adding a widget to the reseter will get its current value and store * it for resetting. To access the value, the given item needs to specify * a value property or implement the {@link qx.ui.core.ISingleSelection} * interface. * * @param item {qx.ui.core.Widget} The widget which should be added. */ add : function(item) { // check the init values if (this._supportsValue(item)) { var init = item.getValue(); } else if (this.__supportsSingleSelection(item)) { var init = item.getSelection(); } else if (this.__supportsDataBindingSelection(item)) { var init = item.getSelection().concat(); } else { throw new Error("Item " + item + " not supported for reseting."); } // store the item and its init value this.__items.push({item: item, init: init}); }, /** * Resets all added form items to their initial value. The initial value * is the value in the widget during the {@link #add}. */ reset: function() { // reset all form items for (var i = 0; i < this.__items.length; i++) { var dataEntry = this.__items[i]; // set the init value this.__setItem(dataEntry.item, dataEntry.init); } }, /** * Resets a single given item. The item has to be added to the resetter * instance before. Otherwise, an error is thrown. * * @param item {qx.ui.core.Widget} The widget, which should be resetted. */ resetItem : function(item) { // get the init value var init; for (var i = 0; i < this.__items.length; i++) { var dataEntry = this.__items[i]; if (dataEntry.item === item) { init = dataEntry.init; break; } }; // check for the available init value if (init === undefined) { throw new Error("The given item has not been added."); } this.__setItem(item, init); }, /** * Internal helper for setting an item to a given init value. It checks * for the supported APIs and uses the fitting API. * * @param item {qx.ui.core.Widget} The item to reset. * @param init {var} The value to set. */ __setItem : function(item, init) { // set the init value if (this._supportsValue(item)) { item.setValue(init); } else if ( this.__supportsSingleSelection(item) || this.__supportsDataBindingSelection(item) ) { item.setSelection(init); } }, /** * Takes the current values of all added items and uses these values as * init values for resetting. */ redefine: function() { // go threw all added items for (var i = 0; i < this.__items.length; i++) { var item = this.__items[i].item; // set the new init value for the item this.__items[i].init = this.__getCurrentValue(item); } }, /** * Takes the current value of the given item and stores this value as init * value for resetting. * * @param item {qx.ui.core.Widget} The item to redefine. */ redefineItem : function(item) { // get the data entry var dataEntry; for (var i = 0; i < this.__items.length; i++) { if (this.__items[i].item === item) { dataEntry = this.__items[i]; break; } }; // check for the available init value if (dataEntry === undefined) { throw new Error("The given item has not been added."); } // set the new init value for the item dataEntry.init = this.__getCurrentValue(dataEntry.item); }, /** * Internel helper top access the value of a given item. * * @param item {qx.ui.core.Widget} The item to access. */ __getCurrentValue : function(item) { if (this._supportsValue(item)) { return item.getValue(); } else if ( this.__supportsSingleSelection(item) || this.__supportsDataBindingSelection(item) ) { return item.getSelection(); } }, /** * Returns true, if the given item implements the * {@link qx.ui.core.ISingleSelection} interface. * * @param formItem {qx.core.Object} The item to check. * @return {boolean} true, if the given item implements the * necessary interface. */ __supportsSingleSelection : function(formItem) { var clazz = formItem.constructor; return qx.Class.hasInterface(clazz, qx.ui.core.ISingleSelection); }, /** * Returns true, if the given item implements the * {@link qx.data.controller.ISelection} interface. * * @param formItem {qx.core.Object} The item to check. * @return {boolean} true, if the given item implements the * necessary interface. */ __supportsDataBindingSelection : function(formItem) { var clazz = formItem.constructor; return qx.Class.hasInterface(clazz, qx.data.controller.ISelection); }, /** * Returns true, if the value property is supplied by the form item. * * @param formItem {qx.core.Object} The item to check. * @return {boolean} true, if the given item implements the * necessary interface. */ _supportsValue : function(formItem) { var clazz = formItem.constructor; return ( qx.Class.hasInterface(clazz, qx.ui.form.IBooleanForm) || qx.Class.hasInterface(clazz, qx.ui.form.IColorForm) || qx.Class.hasInterface(clazz, qx.ui.form.IDateForm) || qx.Class.hasInterface(clazz, qx.ui.form.INumberForm) || qx.Class.hasInterface(clazz, qx.ui.form.IStringForm) ); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { // holding references to widgets --> must set to null this.__items = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2012 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Interface for data binding classes offering a selection. */ qx.Interface.define("qx.data.controller.ISelection", { members : { /** * Setter for the selection. * @param value {qx.data.IListData} The data of the selection. */ setSelection : function(value) {}, /** * Getter for the selection list. * @return {qx.data.IListData} The current selection. */ getSelection : function() {}, /** * Resets the selection to its default value. */ resetSelection : function() {} } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Form interface for all form widgets which have boolean as their primary * data type like a checkbox. */ qx.Interface.define("qx.ui.form.IBooleanForm", { /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fired when the value was modified */ "changeValue" : "qx.event.type.Data" }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /* --------------------------------------------------------------------------- VALUE PROPERTY --------------------------------------------------------------------------- */ /** * Sets the element's value. * * @param value {Boolean|null} The new value of the element. */ setValue : function(value) { return arguments.length == 1; }, /** * Resets the element's value to its initial value. */ resetValue : function() {}, /** * The element's user set value. * * @return {Boolean|null} The value. */ getValue : function() {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Form interface for all form widgets which have boolean as their primary * data type like a colorchooser. */ qx.Interface.define("qx.ui.form.IColorForm", { /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fired when the value was modified */ "changeValue" : "qx.event.type.Data" }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /* --------------------------------------------------------------------------- VALUE PROPERTY --------------------------------------------------------------------------- */ /** * Sets the element's value. * * @param value {Color|null} The new value of the element. */ setValue : function(value) { return arguments.length == 1; }, /** * Resets the element's value to its initial value. */ resetValue : function() {}, /** * The element's user set value. * * @return {Color|null} The value. */ getValue : function() {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Form interface for all form widgets which have date as their primary * data type like datechooser's. */ qx.Interface.define("qx.ui.form.IDateForm", { /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fired when the value was modified */ "changeValue" : "qx.event.type.Data" }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /* --------------------------------------------------------------------------- VALUE PROPERTY --------------------------------------------------------------------------- */ /** * Sets the element's value. * * @param value {Date|null} The new value of the element. */ setValue : function(value) { return arguments.length == 1; }, /** * Resets the element's value to its initial value. */ resetValue : function() {}, /** * The element's user set value. * * @return {Date|null} The value. */ getValue : function() {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Form interface for all form widgets which use a numeric value as their * primary data type like a spinner. */ qx.Interface.define("qx.ui.form.INumberForm", { /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fired when the value was modified */ "changeValue" : "qx.event.type.Data" }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /* --------------------------------------------------------------------------- VALUE PROPERTY --------------------------------------------------------------------------- */ /** * Sets the element's value. * * @param value {Number|null} The new value of the element. */ setValue : function(value) { return arguments.length == 1; }, /** * Resets the element's value to its initial value. */ resetValue : function() {}, /** * The element's user set value. * * @return {Number|null} The value. */ getValue : function() {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * This mixin is included by all widgets, which support an 'execute' like * buttons or menu entries. */ qx.Mixin.define("qx.ui.core.MExecutable", { /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fired if the {@link #execute} method is invoked.*/ "execute" : "qx.event.type.Event" }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * A command called if the {@link #execute} method is called, e.g. on a * button click. */ command : { check : "qx.ui.core.Command", apply : "_applyCommand", event : "changeCommand", nullable : true } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __executableBindingIds : null, __semaphore : false, __executeListenerId : null, /** * {Map} Set of properties, which will by synced from the command to the * including widget * * @lint ignoreReferenceField(_bindableProperties) */ _bindableProperties : [ "enabled", "label", "icon", "toolTipText", "value", "menu" ], /** * Initiate the execute action. */ execute : function() { var cmd = this.getCommand(); if (cmd) { if (this.__semaphore) { this.__semaphore = false; } else { this.__semaphore = true; cmd.execute(this); } } this.fireEvent("execute"); }, /** * Handler for the execute event of the command. * * @param e {qx.event.type.Event} The execute event of the command. */ __onCommandExecute : function(e) { if (this.__semaphore) { this.__semaphore = false; return; } this.__semaphore = true; this.execute(); }, // property apply _applyCommand : function(value, old) { // execute forwarding if (old != null) { old.removeListenerById(this.__executeListenerId); } if (value != null) { this.__executeListenerId = value.addListener( "execute", this.__onCommandExecute, this ); } // binding stuff var ids = this.__executableBindingIds; if (ids == null) { this.__executableBindingIds = ids = {}; } var selfPropertyValue; for (var i = 0; i < this._bindableProperties.length; i++) { var property = this._bindableProperties[i]; // remove the old binding if (old != null && !old.isDisposed() && ids[property] != null) { old.removeBinding(ids[property]); ids[property] = null; } // add the new binding if (value != null && qx.Class.hasProperty(this.constructor, property)) { // handle the init value (dont sync the initial null) var cmdPropertyValue = value.get(property); if (cmdPropertyValue == null) { selfPropertyValue = this.get(property); // check also for themed values [BUG #5906] if (selfPropertyValue == null) { // update the appearance to make sure every themed property is up to date this.syncAppearance(); selfPropertyValue = qx.util.PropertyUtil.getThemeValue( this, property ); } } else { // Reset the self property value [BUG #4534] selfPropertyValue = null; } // set up the binding ids[property] = value.bind(property, this, property); // reapply the former value if (selfPropertyValue) { this.set(property, selfPropertyValue); } } } } }, destruct : function() { this._applyCommand(null, this.getCommand()); this.__executableBindingIds = null; } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A helper class for accessing the property system directly. * * This class is rather to be used internally. For all regular usage of the * property system the default API should be sufficient. */ qx.Class.define("qx.util.PropertyUtil", { statics : { /** * Get the property map of the given class * * @param clazz {Class} a qooxdoo class * @return {Map} A properties map as defined in {@link qx.Class#define} * including the properties of included mixins and not including refined * properties. */ getProperties : function(clazz) { return clazz.$$properties; }, /** * Get the property map of the given class including the properties of all * superclasses! * * @param clazz {Class} a qooxdoo class * @return {Map} The properties map as defined in {@link qx.Class#define} * including the properties of included mixins of the current class and * all superclasses. */ getAllProperties : function(clazz) { var properties = {}; var superclass = clazz; // go threw the class hierarchy while (superclass != qx.core.Object) { var currentProperties = this.getProperties(superclass); for (var property in currentProperties) { properties[property] = currentProperties[property]; } superclass = superclass.superclass; } return properties; }, /* ------------------------------------------------------------------------- USER VALUES ------------------------------------------------------------------------- */ /** * Returns the user value of the given property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @return {var} The user value */ getUserValue : function(object, propertyName) { return object["$$user_" + propertyName]; }, /** * Sets the user value of the given property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @param value {var} The value to set * @return {void} */ setUserValue : function(object, propertyName, value) { object["$$user_" + propertyName] = value; }, /** * Deletes the user value of the given property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @return {void} */ deleteUserValue : function(object, propertyName) { delete(object["$$user_" + propertyName]); }, /* ------------------------------------------------------------------------- INIT VALUES ------------------------------------------------------------------------- */ /** * Returns the init value of the given property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @return {var} The init value */ getInitValue : function(object, propertyName) { return object["$$init_" + propertyName]; }, /** * Sets the init value of the given property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @param value {var} The value to set * @return {void} */ setInitValue : function(object, propertyName, value) { object["$$init_" + propertyName] = value; }, /** * Deletes the init value of the given property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @return {void} */ deleteInitValue : function(object, propertyName) { delete(object["$$init_" + propertyName]); }, /* ------------------------------------------------------------------------- THEME VALUES ------------------------------------------------------------------------- */ /** * Returns the theme value of the given property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @return {var} The theme value */ getThemeValue : function(object, propertyName) { return object["$$theme_" + propertyName]; }, /** * Sets the theme value of the given property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @param value {var} The value to set * @return {void} */ setThemeValue : function(object, propertyName, value) { object["$$theme_" + propertyName] = value; }, /** * Deletes the theme value of the given property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @return {void} */ deleteThemeValue : function(object, propertyName) { delete(object["$$theme_" + propertyName]); }, /* ------------------------------------------------------------------------- THEMED PROPERTY ------------------------------------------------------------------------- */ /** * Sets a themed property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @param value {var} The value to set * @return {void} */ setThemed : function(object, propertyName, value) { var styler = qx.core.Property.$$method.setThemed; object[styler[propertyName]](value); }, /** * Resets a themed property * * @param object {Object} The object to access * @param propertyName {String} The name of the property * @return {void} */ resetThemed : function(object, propertyName) { var unstyler = qx.core.Property.$$method.resetThemed; object[unstyler[propertyName]](); } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Form interface for all form widgets which are executable in some way. This * could be a button for example. */ qx.Interface.define("qx.ui.form.IExecutable", { /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** * Fired when the widget is executed. Sets the "data" property of the * event to the object that issued the command. */ "execute" : "qx.event.type.Data" }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /* --------------------------------------------------------------------------- COMMAND PROPERTY --------------------------------------------------------------------------- */ /** * Set the command of this executable. * * @param command {qx.ui.core.Command} The command. */ setCommand : function(command) { return arguments.length == 1; }, /** * Return the current set command of this executable. * * @return {qx.ui.core.Command} The current set command. */ getCommand : function() {}, /** * Fire the "execute" event on the command. */ execute: function() {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A Button widget which supports various states and allows it to be used * via the mouse and the keyboard. * * If the user presses the button by clicking on it, or the <code>Enter</code> or * <code>Space</code> keys, the button fires an {@link qx.ui.core.MExecutable#execute} event. * * If the {@link qx.ui.core.MExecutable#command} property is set, the * command is executed as well. * * *Example* * * Here is a little example of how to use the widget. * * <pre class='javascript'> * var button = new qx.ui.form.Button("Hello World"); * * button.addListener("execute", function(e) { * alert("Button was clicked"); * }, this); * * this.getRoot.add(button); * </pre> * * This example creates a button with the label "Hello World" and attaches an * event listener to the {@link #execute} event. * * *External Documentation* * * <a href='http://manual.qooxdoo.org/${qxversion}/pages/widget/button.html' target='_blank'> * Documentation of this widget in the qooxdoo manual.</a> */ qx.Class.define("qx.ui.form.Button", { extend : qx.ui.basic.Atom, include : [qx.ui.core.MExecutable], implement : [qx.ui.form.IExecutable], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param label {String} label of the atom * @param icon {String?null} Icon URL of the atom * @param command {qx.ui.core.Command?null} Command instance to connect with */ construct : function(label, icon, command) { this.base(arguments, label, icon); if (command != null) { this.setCommand(command); } // Add listeners this.addListener("mouseover", this._onMouseOver); this.addListener("mouseout", this._onMouseOut); this.addListener("mousedown", this._onMouseDown); this.addListener("mouseup", this._onMouseUp); this.addListener("keydown", this._onKeyDown); this.addListener("keyup", this._onKeyUp); // Stop events this.addListener("dblclick", this._onStopEvent); }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { // overridden appearance : { refine : true, init : "button" }, // overridden focusable : { refine : true, init : true } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { // overridden /** * @lint ignoreReferenceField(_forwardStates) */ _forwardStates : { focused : true, hovered : true, pressed : true, disabled : true }, /* --------------------------------------------------------------------------- USER API --------------------------------------------------------------------------- */ /** * Manually press the button */ press : function() { if (this.hasState("abandoned")) { return; } this.addState("pressed"); }, /** * Manually release the button */ release : function() { if (this.hasState("pressed")) { this.removeState("pressed"); } }, /** * Completely reset the button (remove all states) */ reset : function() { this.removeState("pressed"); this.removeState("abandoned"); this.removeState("hovered"); }, /* --------------------------------------------------------------------------- EVENT LISTENERS --------------------------------------------------------------------------- */ /** * Listener method for "mouseover" event * <ul> * <li>Adds state "hovered"</li> * <li>Removes "abandoned" and adds "pressed" state (if "abandoned" state is set)</li> * </ul> * * @param e {Event} Mouse event * @return {void} */ _onMouseOver : function(e) { if (!this.isEnabled() || e.getTarget() !== this) { return; } if (this.hasState("abandoned")) { this.removeState("abandoned"); this.addState("pressed"); } this.addState("hovered"); }, /** * Listener method for "mouseout" event * <ul> * <li>Removes "hovered" state</li> * <li>Adds "abandoned" and removes "pressed" state (if "pressed" state is set)</li> * </ul> * * @param e {Event} Mouse event * @return {void} */ _onMouseOut : function(e) { if (!this.isEnabled() || e.getTarget() !== this) { return; } this.removeState("hovered"); if (this.hasState("pressed")) { this.removeState("pressed"); this.addState("abandoned"); } }, /** * Listener method for "mousedown" event * <ul> * <li>Removes "abandoned" state</li> * <li>Adds "pressed" state</li> * </ul> * * @param e {Event} Mouse event * @return {void} */ _onMouseDown : function(e) { if (!e.isLeftPressed()) { return; } e.stopPropagation(); // Activate capturing if the button get a mouseout while // the button is pressed. this.capture(); this.removeState("abandoned"); this.addState("pressed"); }, /** * Listener method for "mouseup" event * <ul> * <li>Removes "pressed" state (if set)</li> * <li>Removes "abandoned" state (if set)</li> * <li>Adds "hovered" state (if "abandoned" state is not set)</li> *</ul> * * @param e {Event} Mouse event * @return {void} */ _onMouseUp : function(e) { this.releaseCapture(); // We must remove the states before executing the command // because in cases were the window lost the focus while // executing we get the capture phase back (mouseout). var hasPressed = this.hasState("pressed"); var hasAbandoned = this.hasState("abandoned"); if (hasPressed) { this.removeState("pressed"); } if (hasAbandoned) { this.removeState("abandoned"); } else { this.addState("hovered"); if (hasPressed) { this.execute(); } } e.stopPropagation(); }, /** * Listener method for "keydown" event.<br/> * Removes "abandoned" and adds "pressed" state * for the keys "Enter" or "Space" * * @param e {Event} Key event * @return {void} */ _onKeyDown : function(e) { switch(e.getKeyIdentifier()) { case "Enter": case "Space": this.removeState("abandoned"); this.addState("pressed"); e.stopPropagation(); } }, /** * Listener method for "keyup" event.<br/> * Removes "abandoned" and "pressed" state (if "pressed" state is set) * for the keys "Enter" or "Space" * * @param e {Event} Key event * @return {void} */ _onKeyUp : function(e) { switch(e.getKeyIdentifier()) { case "Enter": case "Space": if (this.hasState("pressed")) { this.removeState("abandoned"); this.removeState("pressed"); this.execute(); e.stopPropagation(); } } } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Mixin handling the valid and required properties for the form widgets. */ qx.Mixin.define("qx.ui.form.MForm", { construct : function() { if (qx.core.Environment.get("qx.dynlocale")) { qx.locale.Manager.getInstance().addListener("changeLocale", this.__onChangeLocale, this); } }, properties : { /** * Flag signaling if a widget is valid. If a widget is invalid, an invalid * state will be set. */ valid : { check : "Boolean", init : true, apply : "_applyValid", event : "changeValid" }, /** * Flag signaling if a widget is required. */ required : { check : "Boolean", init : false, event : "changeRequired" }, /** * Message which is shown in an invalid tooltip. */ invalidMessage : { check : "String", init: "", event : "changeInvalidMessage" }, /** * Message which is shown in an invalid tooltip if the {@link #required} is * set to true. */ requiredInvalidMessage : { check : "String", nullable : true, event : "changeInvalidMessage" } }, members : { // apply method _applyValid: function(value, old) { value ? this.removeState("invalid") : this.addState("invalid"); }, /** * Locale change event handler * * @signature function(e) * @param e {Event} the change event */ __onChangeLocale : qx.core.Environment.select("qx.dynlocale", { "true" : function(e) { // invalid message var invalidMessage = this.getInvalidMessage(); if (invalidMessage && invalidMessage.translate) { this.setInvalidMessage(invalidMessage.translate()); } // required invalid message var requiredInvalidMessage = this.getRequiredInvalidMessage(); if (requiredInvalidMessage && requiredInvalidMessage.translate) { this.setRequiredInvalidMessage(requiredInvalidMessage.translate()); } }, "false" : null }) }, destruct : function() { if (qx.core.Environment.get("qx.dynlocale")) { qx.locale.Manager.getInstance().removeListener("changeLocale", this.__onChangeLocale, this); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Form interface for all widgets which deal with ranges. The spinner is a good * example for a range using widget. */ qx.Interface.define("qx.ui.form.IRange", { /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /* --------------------------------------------------------------------------- MINIMUM PROPERTY --------------------------------------------------------------------------- */ /** * Set the minimum value of the range. * * @param min {Number} The minimum. */ setMinimum : function(min) { return arguments.length == 1; }, /** * Return the current set minimum of the range. * * @return {Number} The current set minimum. */ getMinimum : function() {}, /* --------------------------------------------------------------------------- MAXIMUM PROPERTY --------------------------------------------------------------------------- */ /** * Set the maximum value of the range. * * @param max {Number} The maximum. */ setMaximum : function(max) { return arguments.length == 1; }, /** * Return the current set maximum of the range. * * @return {Number} The current set maximum. */ getMaximum : function() {}, /* --------------------------------------------------------------------------- SINGLESTEP PROPERTY --------------------------------------------------------------------------- */ /** * Sets the value for single steps in the range. * * @param step {Number} The value of the step. */ setSingleStep : function(step) { return arguments.length == 1; }, /** * Returns the value which will be stepped in a single step in the range. * * @return {Number} The current value for single steps. */ getSingleStep : function() {}, /* --------------------------------------------------------------------------- PAGESTEP PROPERTY --------------------------------------------------------------------------- */ /** * Sets the value for page steps in the range. * * @param step {Number} The value of the step. */ setPageStep : function(step) { return arguments.length == 1; }, /** * Returns the value which will be stepped in a page step in the range. * * @return {Number} The current value for page steps. */ getPageStep : function() {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * This mixin defines the <code>contentPadding</code> property, which is used * by widgets like the window or group box, which must have a property, which * defines the padding of an inner pane. * * The including class must implement the method * <code>_getContentPaddingTarget</code>, which must return the widget on which * the padding should be applied. */ qx.Mixin.define("qx.ui.core.MContentPadding", { /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** Top padding of the content pane */ contentPaddingTop : { check : "Integer", init : 0, apply : "_applyContentPadding", themeable : true }, /** Right padding of the content pane */ contentPaddingRight : { check : "Integer", init : 0, apply : "_applyContentPadding", themeable : true }, /** Bottom padding of the content pane */ contentPaddingBottom : { check : "Integer", init : 0, apply : "_applyContentPadding", themeable : true }, /** Left padding of the content pane */ contentPaddingLeft : { check : "Integer", init : 0, apply : "_applyContentPadding", themeable : true }, /** * The 'contentPadding' property is a shorthand property for setting 'contentPaddingTop', * 'contentPaddingRight', 'contentPaddingBottom' and 'contentPaddingLeft' * at the same time. * * If four values are specified they apply to top, right, bottom and left respectively. * If there is only one value, it applies to all sides, if there are two or three, * the missing values are taken from the opposite side. */ contentPadding : { group : [ "contentPaddingTop", "contentPaddingRight", "contentPaddingBottom", "contentPaddingLeft" ], mode : "shorthand", themeable : true } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** * {Map} Maps property names of content padding to the setter of the padding * * @lint ignoreReferenceField(__contentPaddingSetter) */ __contentPaddingSetter : { contentPaddingTop : "setPaddingTop", contentPaddingRight : "setPaddingRight", contentPaddingBottom : "setPaddingBottom", contentPaddingLeft : "setPaddingLeft" }, /** * {Map} Maps property names of content padding to the resetter of the padding * * @lint ignoreReferenceField(__contentPaddingResetter) */ __contentPaddingResetter : { contentPaddingTop : "resetPaddingTop", contentPaddingRight : "resetPaddingRight", contentPaddingBottom : "resetPaddingBottom", contentPaddingLeft : "resetPaddingLeft" }, // property apply _applyContentPadding : function(value, old, name) { var target = this._getContentPaddingTarget(); if (value == null) { var resetter = this.__contentPaddingResetter[name]; target[resetter](); } else { var setter = this.__contentPaddingSetter[name]; target[setter](value); } } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) * Martin Wittemann (martinwittemann) * Jonathan Weiß (jonathan_rass) ************************************************************************ */ /** * A *spinner* is a control that allows you to adjust a numerical value, * typically within an allowed range. An obvious example would be to specify the * month of a year as a number in the range 1 - 12. * * To do so, a spinner encompasses a field to display the current value (a * textfield) and controls such as up and down buttons to change that value. The * current value can also be changed by editing the display field directly, or * using mouse wheel and cursor keys. * * An optional {@link #numberFormat} property allows you to control the format of * how a value can be entered and will be displayed. * * A brief, but non-trivial example: * * <pre class='javascript'> * var s = new qx.ui.form.Spinner(); * s.set({ * maximum: 3000, * minimum: -3000 * }); * var nf = new qx.util.format.NumberFormat(); * nf.setMaximumFractionDigits(2); * s.setNumberFormat(nf); * </pre> * * A spinner instance without any further properties specified in the * constructor or a subsequent *set* command will appear with default * values and behaviour. * * @childControl textfield {qx.ui.form.TextField} holds the current value of the spinner * @childControl upbutton {qx.ui.form.Button} button to increase the value * @childControl downbutton {qx.ui.form.Button} button to decrease the value * */ qx.Class.define("qx.ui.form.Spinner", { extend : qx.ui.core.Widget, implement : [ qx.ui.form.INumberForm, qx.ui.form.IRange, qx.ui.form.IForm ], include : [ qx.ui.core.MContentPadding, qx.ui.form.MForm ], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param min {Number} Minimum value * @param value {Number} Current value * @param max {Number} Maximum value */ construct : function(min, value, max) { this.base(arguments); // MAIN LAYOUT var layout = new qx.ui.layout.Grid(); layout.setColumnFlex(0, 1); layout.setRowFlex(0,1); layout.setRowFlex(1,1); this._setLayout(layout); // EVENTS this.addListener("keydown", this._onKeyDown, this); this.addListener("keyup", this._onKeyUp, this); this.addListener("mousewheel", this._onMouseWheel, this); if (qx.core.Environment.get("qx.dynlocale")) { qx.locale.Manager.getInstance().addListener("changeLocale", this._onChangeLocale, this); } // CREATE CONTROLS this._createChildControl("textfield"); this._createChildControl("upbutton"); this._createChildControl("downbutton"); // INITIALIZATION if (min != null) { this.setMinimum(min); } if (max != null) { this.setMaximum(max); } if (value !== undefined) { this.setValue(value); } else { this.initValue(); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties: { // overridden appearance: { refine : true, init : "spinner" }, // overridden focusable : { refine : true, init : true }, /** The amount to increment on each event (keypress or mousedown) */ singleStep: { check : "Number", init : 1 }, /** The amount to increment on each pageup/pagedown keypress */ pageStep: { check : "Number", init : 10 }, /** minimal value of the Range object */ minimum: { check : "Number", apply : "_applyMinimum", init : 0, event: "changeMinimum" }, /** The value of the spinner. */ value: { check : "this._checkValue(value)", nullable : true, apply : "_applyValue", init : 0, event : "changeValue" }, /** maximal value of the Range object */ maximum: { check : "Number", apply : "_applyMaximum", init : 100, event: "changeMaximum" }, /** whether the value should wrap around */ wrap: { check : "Boolean", init : false, apply : "_applyWrap" }, /** Controls whether the textfield of the spinner is editable or not */ editable : { check : "Boolean", init : true, apply : "_applyEditable" }, /** Controls the display of the number in the textfield */ numberFormat : { check : "qx.util.format.NumberFormat", apply : "_applyNumberFormat", nullable : true }, // overridden allowShrinkY : { refine : true, init : false } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** Saved last value in case invalid text is entered */ __lastValidValue : null, /** Whether the page-up button has been pressed */ __pageUpMode : false, /** Whether the page-down button has been pressed */ __pageDownMode : false, /* --------------------------------------------------------------------------- WIDGET INTERNALS --------------------------------------------------------------------------- */ // overridden _createChildControlImpl : function(id, hash) { var control; switch(id) { case "textfield": control = new qx.ui.form.TextField(); control.setFilter(this._getFilterRegExp()); control.addState("inner"); control.setWidth(40); control.setFocusable(false); control.addListener("changeValue", this._onTextChange, this); this._add(control, {column: 0, row: 0, rowSpan: 2}); break; case "upbutton": control = new qx.ui.form.RepeatButton(); control.addState("inner"); control.setFocusable(false); control.addListener("execute", this._countUp, this); this._add(control, {column: 1, row: 0}); break; case "downbutton": control = new qx.ui.form.RepeatButton(); control.addState("inner"); control.setFocusable(false); control.addListener("execute", this._countDown, this); this._add(control, {column:1, row: 1}); break; } return control || this.base(arguments, id); }, /** * Returns the regular expression used as the text field's filter * * @return {RegExp} The filter RegExp. */ _getFilterRegExp : function() { var decimalSeparator = qx.locale.Number.getDecimalSeparator( qx.locale.Manager.getInstance().getLocale() ); var groupSeparator = qx.locale.Number.getGroupSeparator( qx.locale.Manager.getInstance().getLocale() ); var prefix = ""; var postfix = ""; if (this.getNumberFormat() !== null) { prefix = this.getNumberFormat().getPrefix() || ""; postfix = this.getNumberFormat().getPostfix() || ""; } var filterRegExp = new RegExp("[0-9" + qx.lang.String.escapeRegexpChars(decimalSeparator) + qx.lang.String.escapeRegexpChars(groupSeparator) + qx.lang.String.escapeRegexpChars(prefix) + qx.lang.String.escapeRegexpChars(postfix) + "\-]" ); return filterRegExp; }, // overridden /** * @lint ignoreReferenceField(_forwardStates) */ _forwardStates : { focused : true, invalid : true }, // overridden tabFocus : function() { var field = this.getChildControl("textfield"); field.getFocusElement().focus(); field.selectAllText(); }, /* --------------------------------------------------------------------------- APPLY METHODS --------------------------------------------------------------------------- */ /** * Apply routine for the minimum property. * * It sets the value of the spinner to the maximum of the current spinner * value and the given min property value. * * @param value {Number} The new value of the min property * @param old {Number} The old value of the min property */ _applyMinimum : function(value, old) { if (this.getMaximum() < value) { this.setMaximum(value); } if (this.getValue() < value) { this.setValue(value); } else { this._updateButtons(); } }, /** * Apply routine for the maximum property. * * It sets the value of the spinner to the minimum of the current spinner * value and the given max property value. * * @param value {Number} The new value of the max property * @param old {Number} The old value of the max property */ _applyMaximum : function(value, old) { if (this.getMinimum() > value) { this.setMinimum(value); } if (this.getValue() > value) { this.setValue(value); } else { this._updateButtons(); } }, // overridden _applyEnabled : function(value, old) { this.base(arguments, value, old); this._updateButtons(); }, /** * Check whether the value being applied is allowed. * * If you override this to change the allowed type, you will also * want to override {@link #_applyValue}, {@link #_applyMinimum}, * {@link #_applyMaximum}, {@link #_countUp}, {@link #_countDown}, and * {@link #_onTextChange} methods as those cater specifically to numeric * values. * * @param value {Any} * The value being set * @return {Boolean} * <i>true</i> if the value is allowed; * <i>false> otherwise. */ _checkValue : function(value) { return typeof value === "number" && value >= this.getMinimum() && value <= this.getMaximum(); }, /** * Apply routine for the value property. * * It checks the min and max values, disables / enables the * buttons and handles the wrap around. * * @param value {Number} The new value of the spinner * @param old {Number} The former value of the spinner */ _applyValue: function(value, old) { var textField = this.getChildControl("textfield"); this._updateButtons(); // save the last valid value of the spinner this.__lastValidValue = value; // write the value of the spinner to the textfield if (value !== null) { if (this.getNumberFormat()) { textField.setValue(this.getNumberFormat().format(value)); } else { textField.setValue(value + ""); } } else { textField.setValue(""); } }, /** * Apply routine for the editable property.<br/> * It sets the textfield of the spinner to not read only. * * @param value {Boolean} The new value of the editable property * @param old {Boolean} The former value of the editable property */ _applyEditable : function(value, old) { var textField = this.getChildControl("textfield"); if (textField) { textField.setReadOnly(!value); } }, /** * Apply routine for the wrap property.<br/> * Enables all buttons if the wrapping is enabled. * * @param value {Boolean} The new value of the wrap property * @param old {Boolean} The former value of the wrap property */ _applyWrap : function(value, old) { this._updateButtons(); }, /** * Apply routine for the numberFormat property.<br/> * When setting a number format, the display of the * value in the textfield will be changed immediately. * * @param value {Boolean} The new value of the numberFormat property * @param old {Boolean} The former value of the numberFormat property */ _applyNumberFormat : function(value, old) { var textfield = this.getChildControl("textfield"); textfield.setFilter(this._getFilterRegExp()); this.getNumberFormat().addListener("changeNumberFormat", this._onChangeNumberFormat, this); this._applyValue(this.__lastValidValue, undefined); }, /** * Returns the element, to which the content padding should be applied. * * @return {qx.ui.core.Widget} The content padding target. */ _getContentPaddingTarget : function() { return this.getChildControl("textfield"); }, /** * Checks the min and max values, disables / enables the * buttons and handles the wrap around. */ _updateButtons : function() { var upButton = this.getChildControl("upbutton"); var downButton = this.getChildControl("downbutton"); var value = this.getValue(); if (!this.getEnabled()) { // If Spinner is disabled -> disable buttons upButton.setEnabled(false); downButton.setEnabled(false); } else { if (this.getWrap()) { // If wraped -> always enable buttons upButton.setEnabled(true); downButton.setEnabled(true); } else { // check max value if (value !== null && value < this.getMaximum()) { upButton.setEnabled(true); } else { upButton.setEnabled(false); } // check min value if (value !== null && value > this.getMinimum()) { downButton.setEnabled(true); } else { downButton.setEnabled(false); } } } }, /* --------------------------------------------------------------------------- KEY EVENT-HANDLING --------------------------------------------------------------------------- */ /** * Callback for "keyDown" event.<br/> * Controls the interval mode ("single" or "page") * and the interval increase by detecting "Up"/"Down" * and "PageUp"/"PageDown" keys.<br/> * The corresponding button will be pressed. * * @param e {qx.event.type.KeySequence} keyDown event */ _onKeyDown: function(e) { switch(e.getKeyIdentifier()) { case "PageUp": // mark that the spinner is in page mode and process further this.__pageUpMode = true; case "Up": this.getChildControl("upbutton").press(); break; case "PageDown": // mark that the spinner is in page mode and process further this.__pageDownMode = true; case "Down": this.getChildControl("downbutton").press(); break; default: // Do not stop unused events return; } e.stopPropagation(); e.preventDefault(); }, /** * Callback for "keyUp" event.<br/> * Detecting "Up"/"Down" and "PageUp"/"PageDown" keys.<br/> * Releases the button and disabled the page mode, if necessary. * * @param e {qx.event.type.KeySequence} keyUp event * @return {void} */ _onKeyUp: function(e) { switch(e.getKeyIdentifier()) { case "PageUp": this.getChildControl("upbutton").release(); this.__pageUpMode = false; break; case "Up": this.getChildControl("upbutton").release(); break; case "PageDown": this.getChildControl("downbutton").release(); this.__pageDownMode = false; break; case "Down": this.getChildControl("downbutton").release(); break; } }, /* --------------------------------------------------------------------------- OTHER EVENT HANDLERS --------------------------------------------------------------------------- */ /** * Callback method for the "mouseWheel" event.<br/> * Increments or decrements the value of the spinner. * * @param e {qx.event.type.Mouse} mouseWheel event */ _onMouseWheel: function(e) { var delta = e.getWheelDelta("y"); if (delta > 0) { this._countDown(); } else if (delta < 0) { this._countUp(); } e.stop(); }, /** * Callback method for the "change" event of the textfield. * * @param e {qx.event.type.Event} text change event or blur event */ _onTextChange : function(e) { var textField = this.getChildControl("textfield"); var value; // if a number format is set if (this.getNumberFormat()) { // try to parse the current number using the number format try { value = this.getNumberFormat().parse(textField.getValue()); } catch(ex) { // otherwise, process further } } if (value === undefined) { // try to parse the number as a float value = parseFloat(textField.getValue()); } // if the result is a number if (!isNaN(value)) { // Fix range if (value > this.getMaximum()) { textField.setValue(this.getMaximum() + ""); return; } else if (value < this.getMinimum()) { textField.setValue(this.getMinimum() + ""); return; } // set the value in the spinner this.setValue(value); } else { // otherwise, reset the last valid value this._applyValue(this.__lastValidValue, undefined); } }, /** * Callback method for the locale Manager's "changeLocale" event. * * @param ev {qx.event.type.Event} locale change event */ _onChangeLocale : function(ev) { if (this.getNumberFormat() !== null) { this.setNumberFormat(this.getNumberFormat()); var textfield = this.getChildControl("textfield"); textfield.setFilter(this._getFilterRegExp()); textfield.setValue(this.getNumberFormat().format(this.getValue())); } }, /** * Callback method for the number format's "changeNumberFormat" event. * * @param ev {qx.event.type.Event} number format change event */ _onChangeNumberFormat : function(ev) { var textfield = this.getChildControl("textfield"); textfield.setFilter(this._getFilterRegExp()); textfield.setValue(this.getNumberFormat().format(this.getValue())); }, /* --------------------------------------------------------------------------- INTERVAL HANDLING --------------------------------------------------------------------------- */ /** * Checks if the spinner is in page mode and counts either the single * or page Step up. * */ _countUp: function() { if (this.__pageUpMode) { var newValue = this.getValue() + this.getPageStep(); } else { var newValue = this.getValue() + this.getSingleStep(); } // handle the case where wrapping is enabled if (this.getWrap()) { if (newValue > this.getMaximum()) { var diff = this.getMaximum() - newValue; newValue = this.getMinimum() + diff; } } this.gotoValue(newValue); }, /** * Checks if the spinner is in page mode and counts either the single * or page Step down. * */ _countDown: function() { if (this.__pageDownMode) { var newValue = this.getValue() - this.getPageStep(); } else { var newValue = this.getValue() - this.getSingleStep(); } // handle the case where wrapping is enabled if (this.getWrap()) { if (newValue < this.getMinimum()) { var diff = this.getMinimum() + newValue; newValue = this.getMaximum() - diff; } } this.gotoValue(newValue); }, /** * Normalizes the incoming value to be in the valid range and * applies it to the {@link #value} afterwards. * * @param value {Number} Any number * @return {Number} The normalized number */ gotoValue : function(value) { return this.setValue(Math.min(this.getMaximum(), Math.max(this.getMinimum(), value))); } }, destruct : function() { if (qx.core.Environment.get("qx.dynlocale")) { qx.locale.Manager.getInstance().removeListener("changeLocale", this._onChangeLocale, this); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * The grid layout manager arranges the items in a two dimensional * grid. Widgets can be placed into the grid's cells and may span multiple rows * and columns. * * *Features* * * * Flex values for rows and columns * * Minimal and maximal column and row sizes * * Manually setting of column and row sizes * * Horizontal and vertical alignment * * Horizontal and vertical spacing * * Column and row spans * * Auto-sizing * * *Item Properties* * * <ul> * <li><strong>row</strong> <em>(Integer)</em>: The row of the cell the * widget should occupy. Each cell can only contain one widget. This layout * property is mandatory. * </li> * <li><strong>column</strong> <em>(Integer)</em>: The column of the cell the * widget should occupy. Each cell can only contain one widget. This layout * property is mandatory. * </li> * <li><strong>rowSpan</strong> <em>(Integer)</em>: The number of rows, the * widget should span, starting from the row specified in the <code>row</code> * property. The cells in the spanned rows must be empty as well. * </li> * <li><strong>colSpan</strong> <em>(Integer)</em>: The number of columns, the * widget should span, starting from the column specified in the <code>column</code> * property. The cells in the spanned columns must be empty as well. * </li> * </ul> * * *Example* * * Here is a little example of how to use the grid layout. * * <pre class="javascript"> * var layout = new qx.ui.layout.Grid(); * layout.setRowFlex(0, 1); // make row 0 flexible * layout.setColumnWidth(1, 200); // set with of column 1 to 200 pixel * * var container = new qx.ui.container.Composite(layout); * container.add(new qx.ui.core.Widget(), {row: 0, column: 0}); * container.add(new qx.ui.core.Widget(), {row: 0, column: 1}); * container.add(new qx.ui.core.Widget(), {row: 1, column: 0, rowSpan: 2}); * </pre> * * *External Documentation* * * <a href='http://manual.qooxdoo.org/${qxversion}/pages/layout/grid.html'> * Extended documentation</a> and links to demos of this layout in the qooxdoo manual. */ qx.Class.define("qx.ui.layout.Grid", { extend : qx.ui.layout.Abstract, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param spacingX {Integer?0} The horizontal spacing between grid cells. * Sets {@link #spacingX}. * @param spacingY {Integer?0} The vertical spacing between grid cells. * Sets {@link #spacingY}. */ construct : function(spacingX, spacingY) { this.base(arguments); this.__rowData = []; this.__colData = []; if (spacingX) { this.setSpacingX(spacingX); } if (spacingY) { this.setSpacingY(spacingY); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * The horizontal spacing between grid cells. */ spacingX : { check : "Integer", init : 0, apply : "_applyLayoutChange" }, /** * The vertical spacing between grid cells. */ spacingY : { check : "Integer", init : 0, apply : "_applyLayoutChange" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** {Array} 2D array of grid cell data */ __grid : null, __rowData : null, __colData : null, __colSpans : null, __rowSpans : null, __maxRowIndex : null, __maxColIndex : null, /** {Array} cached row heights */ __rowHeights : null, /** {Array} cached column widths */ __colWidths : null, // overridden verifyLayoutProperty : qx.core.Environment.select("qx.debug", { "true" : function(item, name, value) { var layoutProperties = { "row" : 1, "column" : 1, "rowSpan" : 1, "colSpan" : 1 } this.assert(layoutProperties[name] == 1, "The property '"+name+"' is not supported by the Grid layout!"); this.assertInteger(value); this.assert(value >= 0, "Value must be positive"); }, "false" : null }), /** * Rebuild the internal representation of the grid */ __buildGrid : function() { var grid = []; var colSpans = []; var rowSpans = []; var maxRowIndex = -1; var maxColIndex = -1; var children = this._getLayoutChildren(); for (var i=0,l=children.length; i<l; i++) { var child = children[i]; var props = child.getLayoutProperties(); var row = props.row; var column = props.column; props.colSpan = props.colSpan || 1; props.rowSpan = props.rowSpan || 1; // validate arguments if (row == null || column == null) { throw new Error( "The layout properties 'row' and 'column' of the child widget '" + child + "' must be defined!" ); } if (grid[row] && grid[row][column]) { throw new Error( "Cannot add widget '" + child + "'!. " + "There is already a widget '" + grid[row][column] + "' in this cell (" + row + ", " + column + ") for '" + this + "'" ); } for (var x=column; x<column+props.colSpan; x++) { for (var y=row; y<row+props.rowSpan; y++) { if (grid[y] == undefined) { grid[y] = []; } grid[y][x] = child; maxColIndex = Math.max(maxColIndex, x); maxRowIndex = Math.max(maxRowIndex, y); } } if (props.rowSpan > 1) { rowSpans.push(child); } if (props.colSpan > 1) { colSpans.push(child); } } // make sure all columns are defined so that accessing the grid using // this.__grid[column][row] will never raise an exception for (var y=0; y<=maxRowIndex; y++) { if (grid[y] == undefined) { grid[y] = []; } } this.__grid = grid; this.__colSpans = colSpans; this.__rowSpans = rowSpans; this.__maxRowIndex = maxRowIndex; this.__maxColIndex = maxColIndex; this.__rowHeights = null; this.__colWidths = null; // Clear invalidation marker delete this._invalidChildrenCache; }, /** * Stores data for a grid row * * @param row {Integer} The row index * @param key {String} The key under which the data should be stored * @param value {var} data to store */ _setRowData : function(row, key, value) { var rowData = this.__rowData[row]; if (!rowData) { this.__rowData[row] = {}; this.__rowData[row][key] = value; } else { rowData[key] = value; } }, /** * Stores data for a grid column * * @param column {Integer} The column index * @param key {String} The key under which the data should be stored * @param value {var} data to store */ _setColumnData : function(column, key, value) { var colData = this.__colData[column]; if (!colData) { this.__colData[column] = {}; this.__colData[column][key] = value; } else { colData[key] = value; } }, /** * Shortcut to set both horizontal and vertical spacing between grid cells * to the same value. * * @param spacing {Integer} new horizontal and vertical spacing * @return {qx.ui.layout.Grid} This object (for chaining support). */ setSpacing : function(spacing) { this.setSpacingY(spacing); this.setSpacingX(spacing); return this; }, /** * Set the default cell alignment for a column. This alignment can be * overridden on a per cell basis by setting the cell's content widget's * <code>alignX</code> and <code>alignY</code> properties. * * If on a grid cell both row and a column alignment is set, the horizontal * alignment is taken from the column and the vertical alignment is taken * from the row. * * @param column {Integer} Column index * @param hAlign {String} The horizontal alignment. Valid values are * "left", "center" and "right". * @param vAlign {String} The vertical alignment. Valid values are * "top", "middle", "bottom" * @return {qx.ui.layout.Grid} This object (for chaining support) */ setColumnAlign : function(column, hAlign, vAlign) { if (qx.core.Environment.get("qx.debug")) { this.assertInteger(column, "Invalid parameter 'column'"); this.assertInArray(hAlign, ["left", "center", "right"]); this.assertInArray(vAlign, ["top", "middle", "bottom"]); } this._setColumnData(column, "hAlign", hAlign); this._setColumnData(column, "vAlign", vAlign); this._applyLayoutChange(); return this; }, /** * Get a map of the column's alignment. * * @param column {Integer} The column index * @return {Map} A map with the keys <code>vAlign</code> and <code>hAlign</code> * containing the vertical and horizontal column alignment. */ getColumnAlign : function(column) { var colData = this.__colData[column] || {}; return { vAlign : colData.vAlign || "top", hAlign : colData.hAlign || "left" }; }, /** * Set the default cell alignment for a row. This alignment can be * overridden on a per cell basis by setting the cell's content widget's * <code>alignX</code> and <code>alignY</code> properties. * * If on a grid cell both row and a column alignment is set, the horizontal * alignment is taken from the column and the vertical alignment is taken * from the row. * * @param row {Integer} Row index * @param hAlign {String} The horizontal alignment. Valid values are * "left", "center" and "right". * @param vAlign {String} The vertical alignment. Valid values are * "top", "middle", "bottom" * @return {qx.ui.layout.Grid} This object (for chaining support) */ setRowAlign : function(row, hAlign, vAlign) { if (qx.core.Environment.get("qx.debug")) { this.assertInteger(row, "Invalid parameter 'row'"); this.assertInArray(hAlign, ["left", "center", "right"]); this.assertInArray(vAlign, ["top", "middle", "bottom"]); } this._setRowData(row, "hAlign", hAlign); this._setRowData(row, "vAlign", vAlign); this._applyLayoutChange(); return this; }, /** * Get a map of the row's alignment. * * @param row {Integer} The Row index * @return {Map} A map with the keys <code>vAlign</code> and <code>hAlign</code> * containing the vertical and horizontal row alignment. */ getRowAlign : function(row) { var rowData = this.__rowData[row] || {}; return { vAlign : rowData.vAlign || "top", hAlign : rowData.hAlign || "left" }; }, /** * Get the widget located in the cell. If a the cell is empty or the widget * has a {@link qx.ui.core.Widget#visibility} value of <code>exclude</code>, * <code>null</code> is returned. * * @param row {Integer} The cell's row index * @param column {Integer} The cell's column index * @return {qx.ui.core.Widget|null}The cell's widget. The value may be null. */ getCellWidget : function(row, column) { if (this._invalidChildrenCache) { this.__buildGrid(); } var row = this.__grid[row] || {}; return row[column] || null; }, /** * Get the number of rows in the grid layout. * * @return {Integer} The number of rows in the layout */ getRowCount : function() { if (this._invalidChildrenCache) { this.__buildGrid(); } return this.__maxRowIndex + 1; }, /** * Get the number of columns in the grid layout. * * @return {Integer} The number of columns in the layout */ getColumnCount : function() { if (this._invalidChildrenCache) { this.__buildGrid(); } return this.__maxColIndex + 1; }, /** * Get a map of the cell's alignment. For vertical alignment the row alignment * takes precedence over the column alignment. For horizontal alignment it is * the over way round. If an alignment is set on the cell widget using * {@link qx.ui.core.LayoutItem#setLayoutProperties}, this alignment takes * always precedence over row or column alignment. * * @param row {Integer} The cell's row index * @param column {Integer} The cell's column index * @return {Map} A map with the keys <code>vAlign</code> and <code>hAlign</code> * containing the vertical and horizontal cell alignment. */ getCellAlign : function(row, column) { var vAlign = "top"; var hAlign = "left"; var rowData = this.__rowData[row]; var colData = this.__colData[column]; var widget = this.__grid[row][column]; if (widget) { var widgetProps = { vAlign : widget.getAlignY(), hAlign : widget.getAlignX() } } else { widgetProps = {}; } // compute vAlign // precedence : widget -> row -> column if (widgetProps.vAlign) { vAlign = widgetProps.vAlign; } else if (rowData && rowData.vAlign) { vAlign = rowData.vAlign; } else if (colData && colData.vAlign) { vAlign = colData.vAlign; } // compute hAlign // precedence : widget -> column -> row if (widgetProps.hAlign) { hAlign = widgetProps.hAlign; } else if (colData && colData.hAlign) { hAlign = colData.hAlign; } else if (rowData && rowData.hAlign) { hAlign = rowData.hAlign; } return { vAlign : vAlign, hAlign : hAlign } }, /** * Set the flex value for a grid column. * By default the column flex value is <code>0</code>. * * @param column {Integer} The column index * @param flex {Integer} The column's flex value * @return {qx.ui.layout.Grid} This object (for chaining support) */ setColumnFlex : function(column, flex) { this._setColumnData(column, "flex", flex); this._applyLayoutChange(); return this; }, /** * Get the flex value of a grid column. * * @param column {Integer} The column index * @return {Integer} The column's flex value */ getColumnFlex : function(column) { var colData = this.__colData[column] || {}; return colData.flex !== undefined ? colData.flex : 0; }, /** * Set the flex value for a grid row. * By default the row flex value is <code>0</code>. * * @param row {Integer} The row index * @param flex {Integer} The row's flex value * @return {qx.ui.layout.Grid} This object (for chaining support) */ setRowFlex : function(row, flex) { this._setRowData(row, "flex", flex); this._applyLayoutChange(); return this; }, /** * Get the flex value of a grid row. * * @param row {Integer} The row index * @return {Integer} The row's flex value */ getRowFlex : function(row) { var rowData = this.__rowData[row] || {}; var rowFlex = rowData.flex !== undefined ? rowData.flex : 0 return rowFlex; }, /** * Set the maximum width of a grid column. * The default value is <code>Infinity</code>. * * @param column {Integer} The column index * @param maxWidth {Integer} The column's maximum width * @return {qx.ui.layout.Grid} This object (for chaining support) */ setColumnMaxWidth : function(column, maxWidth) { this._setColumnData(column, "maxWidth", maxWidth); this._applyLayoutChange(); return this; }, /** * Get the maximum width of a grid column. * * @param column {Integer} The column index * @return {Integer} The column's maximum width */ getColumnMaxWidth : function(column) { var colData = this.__colData[column] || {}; return colData.maxWidth !== undefined ? colData.maxWidth : Infinity; }, /** * Set the preferred width of a grid column. * The default value is <code>Infinity</code>. * * @param column {Integer} The column index * @param width {Integer} The column's width * @return {qx.ui.layout.Grid} This object (for chaining support) */ setColumnWidth : function(column, width) { this._setColumnData(column, "width", width); this._applyLayoutChange(); return this; }, /** * Get the preferred width of a grid column. * * @param column {Integer} The column index * @return {Integer} The column's width */ getColumnWidth : function(column) { var colData = this.__colData[column] || {}; return colData.width !== undefined ? colData.width : null; }, /** * Set the minimum width of a grid column. * The default value is <code>0</code>. * * @param column {Integer} The column index * @param minWidth {Integer} The column's minimum width * @return {qx.ui.layout.Grid} This object (for chaining support) */ setColumnMinWidth : function(column, minWidth) { this._setColumnData(column, "minWidth", minWidth); this._applyLayoutChange(); return this; }, /** * Get the minimum width of a grid column. * * @param column {Integer} The column index * @return {Integer} The column's minimum width */ getColumnMinWidth : function(column) { var colData = this.__colData[column] || {}; return colData.minWidth || 0; }, /** * Set the maximum height of a grid row. * The default value is <code>Infinity</code>. * * @param row {Integer} The row index * @param maxHeight {Integer} The row's maximum width * @return {qx.ui.layout.Grid} This object (for chaining support) */ setRowMaxHeight : function(row, maxHeight) { this._setRowData(row, "maxHeight", maxHeight); this._applyLayoutChange(); return this; }, /** * Get the maximum height of a grid row. * * @param row {Integer} The row index * @return {Integer} The row's maximum width */ getRowMaxHeight : function(row) { var rowData = this.__rowData[row] || {}; return rowData.maxHeight || Infinity; }, /** * Set the preferred height of a grid row. * The default value is <code>Infinity</code>. * * @param row {Integer} The row index * @param height {Integer} The row's width * @return {qx.ui.layout.Grid} This object (for chaining support) */ setRowHeight : function(row, height) { this._setRowData(row, "height", height); this._applyLayoutChange(); return this; }, /** * Get the preferred height of a grid row. * * @param row {Integer} The row index * @return {Integer} The row's width */ getRowHeight : function(row) { var rowData = this.__rowData[row] || {}; return rowData.height !== undefined ? rowData.height : null; }, /** * Set the minimum height of a grid row. * The default value is <code>0</code>. * * @param row {Integer} The row index * @param minHeight {Integer} The row's minimum width * @return {qx.ui.layout.Grid} This object (for chaining support) */ setRowMinHeight : function(row, minHeight) { this._setRowData(row, "minHeight", minHeight); this._applyLayoutChange(); return this; }, /** * Get the minimum height of a grid row. * * @param row {Integer} The row index * @return {Integer} The row's minimum width */ getRowMinHeight : function(row) { var rowData = this.__rowData[row] || {}; return rowData.minHeight || 0; }, /** * Computes the widget's size hint including the widget's margins * * @param widget {qx.ui.core.LayoutItem} The widget to get the size for * @return {Map} a size hint map */ __getOuterSize : function(widget) { var hint = widget.getSizeHint(); var hMargins = widget.getMarginLeft() + widget.getMarginRight(); var vMargins = widget.getMarginTop() + widget.getMarginBottom(); var outerSize = { height: hint.height + vMargins, width: hint.width + hMargins, minHeight: hint.minHeight + vMargins, minWidth: hint.minWidth + hMargins, maxHeight: hint.maxHeight + vMargins, maxWidth: hint.maxWidth + hMargins } return outerSize; }, /** * Check whether all row spans fit with their preferred height into the * preferred row heights. If there is not enough space, the preferred * row sizes are increased. The distribution respects the flex and max * values of the rows. * * The same is true for the min sizes. * * The height array is modified in place. * * @param rowHeights {Map[]} The current row height array as computed by * {@link #_getRowHeights}. */ _fixHeightsRowSpan : function(rowHeights) { var vSpacing = this.getSpacingY(); for (var i=0, l=this.__rowSpans.length; i<l; i++) { var widget = this.__rowSpans[i]; var hint = this.__getOuterSize(widget); var widgetProps = widget.getLayoutProperties(); var widgetRow = widgetProps.row; var prefSpanHeight = vSpacing * (widgetProps.rowSpan - 1); var minSpanHeight = prefSpanHeight; var rowFlexes = {}; for (var j=0; j<widgetProps.rowSpan; j++) { var row = widgetProps.row+j; var rowHeight = rowHeights[row]; var rowFlex = this.getRowFlex(row); if (rowFlex > 0) { // compute flex array for the preferred height rowFlexes[row] = { min : rowHeight.minHeight, value : rowHeight.height, max : rowHeight.maxHeight, flex: rowFlex }; } prefSpanHeight += rowHeight.height; minSpanHeight += rowHeight.minHeight; } // If there is not enough space for the preferred size // increment the preferred row sizes. if (prefSpanHeight < hint.height) { if (!qx.lang.Object.isEmpty(rowFlexes)) { var rowIncrements = qx.ui.layout.Util.computeFlexOffsets( rowFlexes, hint.height, prefSpanHeight ); for (var k=0; k<widgetProps.rowSpan; k++) { var offset = rowIncrements[widgetRow+k] ? rowIncrements[widgetRow+k].offset : 0; rowHeights[widgetRow+k].height += offset; } // row is too small and we have no flex value set } else { var totalSpacing = vSpacing * (widgetProps.rowSpan - 1); var availableHeight = hint.height - totalSpacing; // get the row height which every child would need to share the // available hight equally var avgRowHeight = Math.floor(availableHeight / widgetProps.rowSpan); // get the hight already used and the number of children which do // not have at least that avg row height var usedHeight = 0; var rowsNeedAddition = 0; for (var k = 0; k < widgetProps.rowSpan; k++) { var currentHeight = rowHeights[widgetRow + k].height; usedHeight += currentHeight; if (currentHeight < avgRowHeight) { rowsNeedAddition++; } } // the difference of available and used needs to be shared among // those not having the min size var additionalRowHeight = Math.floor((availableHeight - usedHeight) / rowsNeedAddition); // add the extra height to the too small children for (var k = 0; k < widgetProps.rowSpan; k++) { if (rowHeights[widgetRow + k].height < avgRowHeight) { rowHeights[widgetRow + k].height += additionalRowHeight; } } } } // If there is not enough space for the min size // increment the min row sizes. if (minSpanHeight < hint.minHeight) { var rowIncrements = qx.ui.layout.Util.computeFlexOffsets( rowFlexes, hint.minHeight, minSpanHeight ); for (var j=0; j<widgetProps.rowSpan; j++) { var offset = rowIncrements[widgetRow+j] ? rowIncrements[widgetRow+j].offset : 0; rowHeights[widgetRow+j].minHeight += offset; } } } }, /** * Check whether all col spans fit with their preferred width into the * preferred column widths. If there is not enough space the preferred * column sizes are increased. The distribution respects the flex and max * values of the columns. * * The same is true for the min sizes. * * The width array is modified in place. * * @param colWidths {Map[]} The current column width array as computed by * {@link #_getColWidths}. */ _fixWidthsColSpan : function(colWidths) { var hSpacing = this.getSpacingX(); for (var i=0, l=this.__colSpans.length; i<l; i++) { var widget = this.__colSpans[i]; var hint = this.__getOuterSize(widget); var widgetProps = widget.getLayoutProperties(); var widgetColumn = widgetProps.column; var prefSpanWidth = hSpacing * (widgetProps.colSpan - 1); var minSpanWidth = prefSpanWidth; var colFlexes = {}; var offset; for (var j=0; j<widgetProps.colSpan; j++) { var col = widgetProps.column+j; var colWidth = colWidths[col]; var colFlex = this.getColumnFlex(col); // compute flex array for the preferred width if (colFlex > 0) { colFlexes[col] = { min : colWidth.minWidth, value : colWidth.width, max : colWidth.maxWidth, flex: colFlex }; } prefSpanWidth += colWidth.width; minSpanWidth += colWidth.minWidth; } // If there is not enought space for the preferred size // increment the preferred column sizes. if (prefSpanWidth < hint.width) { var colIncrements = qx.ui.layout.Util.computeFlexOffsets( colFlexes, hint.width, prefSpanWidth ); for (var j=0; j<widgetProps.colSpan; j++) { offset = colIncrements[widgetColumn+j] ? colIncrements[widgetColumn+j].offset : 0; colWidths[widgetColumn+j].width += offset; } } // If there is not enought space for the min size // increment the min column sizes. if (minSpanWidth < hint.minWidth) { var colIncrements = qx.ui.layout.Util.computeFlexOffsets( colFlexes, hint.minWidth, minSpanWidth ); for (var j=0; j<widgetProps.colSpan; j++) { offset = colIncrements[widgetColumn+j] ? colIncrements[widgetColumn+j].offset : 0; colWidths[widgetColumn+j].minWidth += offset; } } } }, /** * Compute the min/pref/max row heights. * * @return {Map[]} An array containg height information for each row. The * entries have the keys <code>minHeight</code>, <code>maxHeight</code> and * <code>height</code>. */ _getRowHeights : function() { if (this.__rowHeights != null) { return this.__rowHeights; } var rowHeights = []; var maxRowIndex = this.__maxRowIndex; var maxColIndex = this.__maxColIndex; for (var row=0; row<=maxRowIndex; row++) { var minHeight = 0; var height = 0; var maxHeight = 0; for (var col=0; col<=maxColIndex; col++) { var widget = this.__grid[row][col]; if (!widget) { continue; } // ignore rows with row spans at this place // these rows will be taken into account later var widgetRowSpan = widget.getLayoutProperties().rowSpan || 0; if (widgetRowSpan > 1) { continue; } var cellSize = this.__getOuterSize(widget); if (this.getRowFlex(row) > 0) { minHeight = Math.max(minHeight, cellSize.minHeight); } else { minHeight = Math.max(minHeight, cellSize.height); } height = Math.max(height, cellSize.height); } var minHeight = Math.max(minHeight, this.getRowMinHeight(row)); var maxHeight = this.getRowMaxHeight(row); if (this.getRowHeight(row) !== null) { var height = this.getRowHeight(row); } else { var height = Math.max(minHeight, Math.min(height, maxHeight)); } rowHeights[row] = { minHeight : minHeight, height : height, maxHeight : maxHeight }; } if (this.__rowSpans.length > 0) { this._fixHeightsRowSpan(rowHeights); } this.__rowHeights = rowHeights; return rowHeights; }, /** * Compute the min/pref/max column widths. * * @return {Map[]} An array containg width information for each column. The * entries have the keys <code>minWidth</code>, <code>maxWidth</code> and * <code>width</code>. */ _getColWidths : function() { if (this.__colWidths != null) { return this.__colWidths; } var colWidths = []; var maxColIndex = this.__maxColIndex; var maxRowIndex = this.__maxRowIndex; for (var col=0; col<=maxColIndex; col++) { var width = 0; var minWidth = 0; var maxWidth = Infinity; for (var row=0; row<=maxRowIndex; row++) { var widget = this.__grid[row][col]; if (!widget) { continue; } // ignore columns with col spans at this place // these columns will be taken into account later var widgetColSpan = widget.getLayoutProperties().colSpan || 0; if (widgetColSpan > 1) { continue; } var cellSize = this.__getOuterSize(widget); if (this.getColumnFlex(col) > 0) { minWidth = Math.max(minWidth, cellSize.minWidth); } else { minWidth = Math.max(minWidth, cellSize.width); } width = Math.max(width, cellSize.width); } minWidth = Math.max(minWidth, this.getColumnMinWidth(col)); maxWidth = this.getColumnMaxWidth(col); if (this.getColumnWidth(col) !== null) { var width = this.getColumnWidth(col); } else { var width = Math.max(minWidth, Math.min(width, maxWidth)); } colWidths[col] = { minWidth: minWidth, width : width, maxWidth : maxWidth }; } if (this.__colSpans.length > 0) { this._fixWidthsColSpan(colWidths); } this.__colWidths = colWidths; return colWidths; }, /** * Computes for each column by how many pixels it must grow or shrink, taking * the column flex values and min/max widths into account. * * @param width {Integer} The grid width * @return {Integer[]} Sparse array of offsets to add to each column width. If * an array entry is empty nothing should be added to the column. */ _getColumnFlexOffsets : function(width) { var hint = this.getSizeHint(); var diff = width - hint.width; if (diff == 0) { return {}; } // collect all flexible children var colWidths = this._getColWidths(); var flexibles = {}; for (var i=0, l=colWidths.length; i<l; i++) { var col = colWidths[i]; var colFlex = this.getColumnFlex(i); if ( (colFlex <= 0) || (col.width == col.maxWidth && diff > 0) || (col.width == col.minWidth && diff < 0) ) { continue; } flexibles[i] ={ min : col.minWidth, value : col.width, max : col.maxWidth, flex : colFlex }; } return qx.ui.layout.Util.computeFlexOffsets(flexibles, width, hint.width); }, /** * Computes for each row by how many pixels it must grow or shrink, taking * the row flex values and min/max heights into account. * * @param height {Integer} The grid height * @return {Integer[]} Sparse array of offsets to add to each row height. If * an array entry is empty nothing should be added to the row. */ _getRowFlexOffsets : function(height) { var hint = this.getSizeHint(); var diff = height - hint.height; if (diff == 0) { return {}; } // collect all flexible children var rowHeights = this._getRowHeights(); var flexibles = {}; for (var i=0, l=rowHeights.length; i<l; i++) { var row = rowHeights[i]; var rowFlex = this.getRowFlex(i); if ( (rowFlex <= 0) || (row.height == row.maxHeight && diff > 0) || (row.height == row.minHeight && diff < 0) ) { continue; } flexibles[i] = { min : row.minHeight, value : row.height, max : row.maxHeight, flex : rowFlex }; } return qx.ui.layout.Util.computeFlexOffsets(flexibles, height, hint.height); }, // overridden renderLayout : function(availWidth, availHeight) { if (this._invalidChildrenCache) { this.__buildGrid(); } var Util = qx.ui.layout.Util; var hSpacing = this.getSpacingX(); var vSpacing = this.getSpacingY(); // calculate column widths var prefWidths = this._getColWidths(); var colStretchOffsets = this._getColumnFlexOffsets(availWidth); var colWidths = []; var maxColIndex = this.__maxColIndex; var maxRowIndex = this.__maxRowIndex; var offset; for (var col=0; col<=maxColIndex; col++) { offset = colStretchOffsets[col] ? colStretchOffsets[col].offset : 0; colWidths[col] = prefWidths[col].width + offset; } // calculate row heights var prefHeights = this._getRowHeights(); var rowStretchOffsets = this._getRowFlexOffsets(availHeight); var rowHeights = []; for (var row=0; row<=maxRowIndex; row++) { offset = rowStretchOffsets[row] ? rowStretchOffsets[row].offset : 0; rowHeights[row] = prefHeights[row].height + offset; } // do the layout var left = 0; for (var col=0; col<=maxColIndex; col++) { var top = 0; for (var row=0; row<=maxRowIndex; row++) { var widget = this.__grid[row][col]; // ignore empty cells if (!widget) { top += rowHeights[row] + vSpacing; continue; } var widgetProps = widget.getLayoutProperties(); // ignore cells, which have cell spanning but are not the origin // of the widget if(widgetProps.row !== row || widgetProps.column !== col) { top += rowHeights[row] + vSpacing; continue; } // compute sizes width including cell spanning var spanWidth = hSpacing * (widgetProps.colSpan - 1); for (var i=0; i<widgetProps.colSpan; i++) { spanWidth += colWidths[col+i]; } var spanHeight = vSpacing * (widgetProps.rowSpan - 1); for (var i=0; i<widgetProps.rowSpan; i++) { spanHeight += rowHeights[row+i]; } var cellHint = widget.getSizeHint(); var marginTop = widget.getMarginTop(); var marginLeft = widget.getMarginLeft(); var marginBottom = widget.getMarginBottom(); var marginRight = widget.getMarginRight(); var cellWidth = Math.max(cellHint.minWidth, Math.min(spanWidth-marginLeft-marginRight, cellHint.maxWidth)); var cellHeight = Math.max(cellHint.minHeight, Math.min(spanHeight-marginTop-marginBottom, cellHint.maxHeight)); var cellAlign = this.getCellAlign(row, col); var cellLeft = left + Util.computeHorizontalAlignOffset(cellAlign.hAlign, cellWidth, spanWidth, marginLeft, marginRight); var cellTop = top + Util.computeVerticalAlignOffset(cellAlign.vAlign, cellHeight, spanHeight, marginTop, marginBottom); widget.renderLayout( cellLeft, cellTop, cellWidth, cellHeight ); top += rowHeights[row] + vSpacing; } left += colWidths[col] + hSpacing; } }, // overridden invalidateLayoutCache : function() { this.base(arguments); this.__colWidths = null; this.__rowHeights = null; }, // overridden _computeSizeHint : function() { if (this._invalidChildrenCache) { this.__buildGrid(); } // calculate col widths var colWidths = this._getColWidths(); var minWidth=0, width=0; for (var i=0, l=colWidths.length; i<l; i++) { var col = colWidths[i]; if (this.getColumnFlex(i) > 0) { minWidth += col.minWidth; } else { minWidth += col.width; } width += col.width; } // calculate row heights var rowHeights = this._getRowHeights(); var minHeight=0, height=0; for (var i=0, l=rowHeights.length; i<l; i++) { var row = rowHeights[i]; if (this.getRowFlex(i) > 0) { minHeight += row.minHeight; } else { minHeight += row.height; } height += row.height; } var spacingX = this.getSpacingX() * (colWidths.length - 1); var spacingY = this.getSpacingY() * (rowHeights.length - 1); var hint = { minWidth : minWidth + spacingX, width : width + spacingX, minHeight : minHeight + spacingY, height : height + spacingY }; return hint; } }, /* ***************************************************************************** DESTRUCT ***************************************************************************** */ destruct : function() { this.__grid = this.__rowData = this.__colData = this.__colSpans = this.__rowSpans = this.__colWidths = this.__rowHeights = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * This is a basic form field with common functionality for * {@link TextArea} and {@link TextField}. * * On every keystroke the value is synchronized with the * value of the textfield. Value changes can be monitored by listening to the * {@link #input} or {@link #changeValue} events, respectively. */ qx.Class.define("qx.ui.form.AbstractField", { extend : qx.ui.core.Widget, implement : [ qx.ui.form.IStringForm, qx.ui.form.IForm ], include : [ qx.ui.form.MForm ], type : "abstract", /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param value {String} initial text value of the input field ({@link #setValue}). */ construct : function(value) { this.base(arguments); // shortcut for placeholder feature detection this.__useQxPlaceholder = !qx.core.Environment.get("css.placeholder") || (qx.core.Environment.get("engine.name") == "gecko" && parseFloat(qx.core.Environment.get("engine.version")) >= 2); if (value != null) { this.setValue(value); } this.getContentElement().addListener( "change", this._onChangeContent, this ); // use qooxdoo placeholder if no native placeholder is supported if (this.__useQxPlaceholder) { // assign the placeholder text after the appearance has been applied this.addListener("syncAppearance", this._syncPlaceholder, this); } // translation support if (qx.core.Environment.get("qx.dynlocale")) { qx.locale.Manager.getInstance().addListener( "changeLocale", this._onChangeLocale, this ); } }, /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** * The event is fired on every keystroke modifying the value of the field. * * The method {@link qx.event.type.Data#getData} returns the * current value of the text field. */ "input" : "qx.event.type.Data", /** * The event is fired each time the text field looses focus and the * text field values has changed. * * If you change {@link #liveUpdate} to true, the changeValue event will * be fired after every keystroke and not only after every focus loss. In * that mode, the changeValue event is equal to the {@link #input} event. * * The method {@link qx.event.type.Data#getData} returns the * current text value of the field. */ "changeValue" : "qx.event.type.Data" }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * Alignment of the text */ textAlign : { check : [ "left", "center", "right" ], nullable : true, themeable : true, apply : "_applyTextAlign" }, /** Whether the field is read only */ readOnly : { check : "Boolean", apply : "_applyReadOnly", event : "changeReadOnly", init : false }, // overridden selectable : { refine : true, init : true }, // overridden focusable : { refine : true, init : true }, /** Maximal number of characters that can be entered in the TextArea. */ maxLength : { check : "PositiveInteger", init : Infinity }, /** * Whether the {@link #changeValue} event should be fired on every key * input. If set to true, the changeValue event is equal to the * {@link #input} event. */ liveUpdate : { check : "Boolean", init : false }, /** * String value which will be shown as a hint if the field is all of: * unset, unfocused and enabled. Set to null to not show a placeholder * text. */ placeholder : { check : "String", nullable : true, apply : "_applyPlaceholder" }, /** * RegExp responsible for filtering the value of the textfield. the RegExp * gives the range of valid values. * The following example only allows digits in the textfield. * <pre class='javascript'>field.setFilter(/[0-9]/);</pre> */ filter : { check : "RegExp", nullable : true, init : null } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __nullValue : true, __placeholder : null, __oldValue : null, __oldInputValue : null, __useQxPlaceholder : true, __font : null, __webfontListenerId : null, /* --------------------------------------------------------------------------- WIDGET API --------------------------------------------------------------------------- */ // overridden getFocusElement : function() { var el = this.getContentElement(); if (el) { return el; } }, /** * Creates the input element. Derived classes may override this * method, to create different input elements. * * @return {qx.html.Input} a new input element. */ _createInputElement : function() { return new qx.html.Input("text"); }, // overridden renderLayout : function(left, top, width, height) { var updateInsets = this._updateInsets; var changes = this.base(arguments, left, top, width, height); // Directly return if superclass has detected that no // changes needs to be applied if (!changes) { return; } var inner = changes.size || updateInsets; var pixel = "px"; if (inner || changes.local || changes.margin) { var insets = this.getInsets(); var innerWidth = width - insets.left - insets.right; var innerHeight = height - insets.top - insets.bottom; // ensure that the width and height never get negative innerWidth = innerWidth < 0 ? 0 : innerWidth; innerHeight = innerHeight < 0 ? 0 : innerHeight; } var input = this.getContentElement(); // we don't need to update positions on native placeholders if (updateInsets && this.__useQxPlaceholder) { // render the placeholder this.__getPlaceholderElement().setStyles({ "left": insets.left + pixel, "top": insets.top + pixel }); } if (inner) { // we don't need to update dimensions on native placeholders if (this.__useQxPlaceholder) { this.__getPlaceholderElement().setStyles({ "width": innerWidth + pixel, "height": innerHeight + pixel }); } input.setStyles({ "width": innerWidth + pixel, "height": innerHeight + pixel }); this._renderContentElement(innerHeight, input); } }, /** * Hook into {@link qx.ui.form.AbstractField#renderLayout} method. * Called after the contentElement has a width and an innerWidth. * * Note: This was introduced to fix BUG#1585 * * @param innerHeight {Integer} The inner height of the element. * @param element {Element} The element. */ _renderContentElement : function(innerHeight, element) { //use it in child classes }, // overridden _createContentElement : function() { // create and add the input element var el = this._createInputElement(); // Apply styles el.setStyles( { "border": "none", "padding": 0, "margin": 0, "display" : "block", "background" : "transparent", "outline": "none", "appearance": "none", "position": "absolute", "autoComplete": "off" }); // initialize the html input el.setSelectable(this.getSelectable()); el.setEnabled(this.getEnabled()); // Add listener for input event el.addListener("input", this._onHtmlInput, this); // Disable HTML5 spell checking el.setAttribute("spellcheck", "false"); // Block resize handle el.setStyle("resize", "none"); // IE8 in standard mode needs some extra love here to receive events. if ((qx.core.Environment.get("engine.name") == "mshtml")) { el.setStyles({ backgroundImage: "url(" + qx.util.ResourceManager.getInstance().toUri("qx/static/blank.gif") + ")" }); } return el; }, // overridden _applyEnabled : function(value, old) { this.base(arguments, value, old); this.getContentElement().setEnabled(value); if (this.__useQxPlaceholder) { if (value) { this._showPlaceholder(); } else { this._removePlaceholder(); } } else { var input = this.getContentElement(); // remove the placeholder on disabled input elements input.setAttribute("placeholder", value ? this.getPlaceholder() : ""); } }, // default text sizes /** * @lint ignoreReferenceField(__textSize) */ __textSize : { width : 16, height : 16 }, // overridden _getContentHint : function() { return { width : this.__textSize.width * 10, height : this.__textSize.height || 16 }; }, // overridden _applyFont : function(value, old) { if (old && this.__font && this.__webfontListenerId) { this.__font.removeListenerById(this.__webfontListenerId); this.__webfontListenerId = null; } // Apply var styles; if (value) { this.__font = qx.theme.manager.Font.getInstance().resolve(value); if (this.__font instanceof qx.bom.webfonts.WebFont) { this.__webfontListenerId = this.__font.addListener("changeStatus", this._onWebFontStatusChange, this); } styles = this.__font.getStyles(); } else { styles = qx.bom.Font.getDefaultStyles(); } // check if text color already set - if so this local value has higher priority if (this.getTextColor() != null) { delete styles["color"]; } // apply the font to the content element this.getContentElement().setStyles(styles); // the font will adjust automatically on native placeholders if (this.__useQxPlaceholder) { // don't apply the color to the placeholder delete styles["color"]; // apply the font to the placeholder this.__getPlaceholderElement().setStyles(styles); } // Compute text size if (value) { this.__textSize = qx.bom.Label.getTextSize("A", styles); } else { delete this.__textSize; } // Update layout qx.ui.core.queue.Layout.add(this); }, // overridden _applyTextColor : function(value, old) { if (value) { this.getContentElement().setStyle( "color", qx.theme.manager.Color.getInstance().resolve(value) ); } else { this.getContentElement().removeStyle("color"); } }, // overridden tabFocus : function() { this.base(arguments); this.selectAllText(); }, /** * Returns the text size. * @return {Map} The text size. */ _getTextSize : function() { return this.__textSize; }, /* --------------------------------------------------------------------------- EVENTS --------------------------------------------------------------------------- */ /** * Event listener for native input events. Redirects the event * to the widget. Also checks for the filter and max length. * * @param e {qx.event.type.Data} Input event */ _onHtmlInput : function(e) { var value = e.getData(); var fireEvents = true; this.__nullValue = false; // value unchanged; Firefox fires "input" when pressing ESC [BUG #5309] if (this.__oldInputValue && this.__oldInputValue === value) { fireEvents = false; } // check for the filter if (this.getFilter() != null) { var filteredValue = ""; var index = value.search(this.getFilter()); var processedValue = value; while(index >= 0) { filteredValue = filteredValue + (processedValue.charAt(index)); processedValue = processedValue.substring(index + 1, processedValue.length); index = processedValue.search(this.getFilter()); } if (filteredValue != value) { fireEvents = false; value = filteredValue; this.getContentElement().setValue(value); } } // check for the max length if (value.length > this.getMaxLength()) { fireEvents = false; this.getContentElement().setValue( value.substr(0, this.getMaxLength()) ); } // fire the events, if necessary if (fireEvents) { // store the old input value this.fireDataEvent("input", value, this.__oldInputValue); this.__oldInputValue = value; // check for the live change event if (this.getLiveUpdate()) { this.__fireChangeValueEvent(value); } } }, /** * Triggers text size recalculation after a web font was loaded * * @param ev {qx.event.type.Data} "changeStatus" event */ _onWebFontStatusChange : function(ev) { if (ev.getData().valid === true) { var styles = this.__font.getStyles(); this.__textSize = qx.bom.Label.getTextSize("A", styles); qx.ui.core.queue.Layout.add(this); } }, /** * Handles the firing of the changeValue event including the local cache * for sending the old value in the event. * * @param value {String} The new value. */ __fireChangeValueEvent : function(value) { var old = this.__oldValue; this.__oldValue = value; if (old != value) { this.fireNonBubblingEvent( "changeValue", qx.event.type.Data, [value, old] ); } }, /* --------------------------------------------------------------------------- TEXTFIELD VALUE API --------------------------------------------------------------------------- */ /** * Sets the value of the textfield to the given value. * * @param value {String} The new value */ setValue : function(value) { // handle null values if (value === null) { // just do nothing if null is already set if (this.__nullValue) { return value; } value = ""; this.__nullValue = true; } else { this.__nullValue = false; // native placeholders will be removed by the browser if (this.__useQxPlaceholder) { this._removePlaceholder(); } } if (qx.lang.Type.isString(value)) { var elem = this.getContentElement(); if (value.length > this.getMaxLength()) { value = value.substr(0, this.getMaxLength()); } if (elem.getValue() != value) { var oldValue = elem.getValue(); elem.setValue(value); var data = this.__nullValue ? null : value; this.__oldValue = oldValue; this.__fireChangeValueEvent(data); } // native placeholders will be shown by the browser if (this.__useQxPlaceholder) { this._showPlaceholder(); } return value; } throw new Error("Invalid value type: " + value); }, /** * Returns the current value of the textfield. * * @return {String|null} The current value */ getValue : function() { var value = this.getContentElement().getValue(); return this.__nullValue ? null : value; }, /** * Resets the value to the default */ resetValue : function() { this.setValue(null); }, /** * Event listener for change event of content element * * @param e {qx.event.type.Data} Incoming change event */ _onChangeContent : function(e) { this.__nullValue = e.getData() === null; this.__fireChangeValueEvent(e.getData()); }, /* --------------------------------------------------------------------------- TEXTFIELD SELECTION API --------------------------------------------------------------------------- */ /** * Returns the current selection. * This method only works if the widget is already created and * added to the document. * * @return {String|null} */ getTextSelection : function() { return this.getContentElement().getTextSelection(); }, /** * Returns the current selection length. * This method only works if the widget is already created and * added to the document. * * @return {Integer|null} */ getTextSelectionLength : function() { return this.getContentElement().getTextSelectionLength(); }, /** * Returns the start of the text selection * * @return {Integer|null} Start of selection or null if not available */ getTextSelectionStart : function() { return this.getContentElement().getTextSelectionStart(); }, /** * Returns the end of the text selection * * @return {Integer|null} End of selection or null if not available */ getTextSelectionEnd : function() { return this.getContentElement().getTextSelectionEnd(); }, /** * Set the selection to the given start and end (zero-based). * If no end value is given the selection will extend to the * end of the textfield's content. * This method only works if the widget is already created and * added to the document. * * @param start {Integer} start of the selection (zero-based) * @param end {Integer} end of the selection * @return {void} */ setTextSelection : function(start, end) { this.getContentElement().setTextSelection(start, end); }, /** * Clears the current selection. * This method only works if the widget is already created and * added to the document. * * @return {void} */ clearTextSelection : function() { this.getContentElement().clearTextSelection(); }, /** * Selects the whole content * * @return {void} */ selectAllText : function() { this.setTextSelection(0); }, /* --------------------------------------------------------------------------- PLACEHOLDER HELPER --------------------------------------------------------------------------- */ /** * Helper to show the placeholder text in the field. It checks for all * states and possible conditions and shows the placeholder only if allowed. */ _showPlaceholder : function() { var fieldValue = this.getValue() || ""; var placeholder = this.getPlaceholder(); if ( placeholder != null && fieldValue == "" && !this.hasState("focused") && !this.hasState("disabled") ) { if (this.hasState("showingPlaceholder")) { this._syncPlaceholder(); } else { // the placeholder will be set as soon as the appearance is applied this.addState("showingPlaceholder"); } } }, /** * Helper to remove the placeholder. Deletes the placeholder text from the * field and removes the state. */ _removePlaceholder: function() { if (this.hasState("showingPlaceholder")) { this.__getPlaceholderElement().setStyle("visibility", "hidden"); this.removeState("showingPlaceholder"); } }, /** * Updates the placeholder text with the DOM */ _syncPlaceholder : function () { if (this.hasState("showingPlaceholder")) { this.__getPlaceholderElement().setStyle("visibility", "visible"); } }, /** * Returns the placeholder label and creates it if necessary. */ __getPlaceholderElement : function() { if (this.__placeholder == null) { // create the placeholder this.__placeholder = new qx.html.Label(); var colorManager = qx.theme.manager.Color.getInstance(); this.__placeholder.setStyles({ "visibility" : "hidden", "zIndex" : 6, "position" : "absolute", "color" : colorManager.resolve("text-placeholder") }); this.getContainerElement().add(this.__placeholder); } return this.__placeholder; }, /** * Locale change event handler * * @signature function(e) * @param e {Event} the change event */ _onChangeLocale : qx.core.Environment.select("qx.dynlocale", { "true" : function(e) { var content = this.getPlaceholder(); if (content && content.translate) { this.setPlaceholder(content.translate()); } }, "false" : null }), /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyPlaceholder : function(value, old) { if (this.__useQxPlaceholder) { this.__getPlaceholderElement().setValue(value); if (value != null) { this.addListener("focusin", this._removePlaceholder, this); this.addListener("focusout", this._showPlaceholder, this); this._showPlaceholder(); } else { this.removeListener("focusin", this._removePlaceholder, this); this.removeListener("focusout", this._showPlaceholder, this); this._removePlaceholder(); } } else { // only apply if the widget is enabled if (this.getEnabled()) { this.getContentElement().setAttribute("placeholder", value); } } }, // property apply _applyTextAlign : function(value, old) { this.getContentElement().setStyle("textAlign", value); }, // property apply _applyReadOnly : function(value, old) { var element = this.getContentElement(); element.setAttribute("readOnly", value); if (value) { this.addState("readonly"); this.setFocusable(false); } else { this.removeState("readonly"); this.setFocusable(true); } } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this.__placeholder = this.__font = null; if (qx.core.Environment.get("qx.dynlocale")) { qx.locale.Manager.getInstance().removeListener("changeLocale", this._onChangeLocale, this); } if (this.__font && this.__webfontListenerId) { this.__font.removeListenerById(this.__webfontListenerId); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A Input wrap any valid HTML input element and make it accessible * through the normalized qooxdoo element interface. */ qx.Class.define("qx.html.Input", { extend : qx.html.Element, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param type {String} The type of the input field. Valid values are * <code>text</code>, <code>textarea</code>, <code>select</code>, * <code>checkbox</code>, <code>radio</code>, <code>password</code>, * <code>hidden</code>, <code>submit</code>, <code>image</code>, * <code>file</code>, <code>search</code>, <code>reset</code>, * <code>select</code> and <code>textarea</code>. * @param styles {Map?null} optional map of CSS styles, where the key is the name * of the style and the value is the value to use. * @param attributes {Map?null} optional map of element attributes, where the * key is the name of the attribute and the value is the value to use. */ construct : function(type, styles, attributes) { // Update node name correctly if (type === "select" || type === "textarea") { var nodeName = type; } else { nodeName = "input"; } this.base(arguments, nodeName, styles, attributes); this.__type = type; }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __type : null, // used for webkit only __selectable : null, __enabled : null, /* --------------------------------------------------------------------------- ELEMENT API --------------------------------------------------------------------------- */ //overridden _createDomElement : function() { return qx.bom.Input.create(this.__type); }, // overridden _applyProperty : function(name, value) { this.base(arguments, name, value); var element = this.getDomElement(); if (name === "value") { qx.bom.Input.setValue(element, value); } else if (name === "wrap") { qx.bom.Input.setWrap(element, value); // qx.bom.Input#setWrap has the side-effect that the CSS property // overflow is set via DOM methods, causing queue and DOM to get // out of sync. Mirror all overflow properties to handle the case // when group and x/y property differ. this.setStyle("overflow", element.style.overflow, true); this.setStyle("overflowX", element.style.overflowX, true); this.setStyle("overflowY", element.style.overflowY, true); } }, /** * Set the input element enabled / disabled. * Webkit needs a special treatment because the set color of the input * field changes automatically. Therefore, we use * <code>-webkit-user-modify: read-only</code> and * <code>-webkit-user-select: none</code> * for disabling the fields in webkit. All other browsers use the disabled * attribute. * * @param value {Boolean} true, if the inpout element should be enabled. */ setEnabled : qx.core.Environment.select("engine.name", { "webkit" : function(value) { this.__enabled = value; if (!value) { this.setStyles({ "userModify": "read-only", "userSelect": "none" }); } else { this.setStyles({ "userModify": null, "userSelect": this.__selectable ? null : "none" }); } }, "default" : function(value) { this.setAttribute("disabled", value===false); } }), /** * Set whether the element is selectable. It uses the qooxdoo attribute * qxSelectable with the values 'on' or 'off'. * In webkit, a special css property will be used and checks for the * enabled state. * * @param value {Boolean} True, if the element should be selectable. */ setSelectable : qx.core.Environment.select("engine.name", { "webkit" : function(value) { this.__selectable = value; // Only apply the value when it is enabled this.base(arguments, this.__enabled && value); }, "default" : function(value) { this.base(arguments, value); } }), /* --------------------------------------------------------------------------- INPUT API --------------------------------------------------------------------------- */ /** * Sets the value of the input element. * * @param value {var} the new value * @return {qx.html.Input} This instance for for chaining support. */ setValue : function(value) { var element = this.getDomElement(); if (element) { // Do not overwrite when already correct (on input events) // This is needed to keep caret position while typing. if (element.value != value) { qx.bom.Input.setValue(element, value); } } else { this._setProperty("value", value); } return this; }, /** * Get the current value. * * @return {String} The element's current value. */ getValue : function() { var element = this.getDomElement(); if (element) { return qx.bom.Input.getValue(element); } return this._getProperty("value") || ""; }, /** * Sets the text wrap behavior of a text area element. * * This property uses the style property "wrap" (IE) respectively "whiteSpace" * * @param wrap {Boolean} Whether to turn text wrap on or off. * @param direct {Boolean?false} Whether the execution should be made * directly when possible * @return {qx.html.Input} This instance for for chaining support. */ setWrap : function(wrap, direct) { if (this.__type === "textarea") { this._setProperty("wrap", wrap, direct); } else { throw new Error("Text wrapping is only support by textareas!"); } return this; }, /** * Gets the text wrap behavior of a text area element. * * This property uses the style property "wrap" (IE) respectively "whiteSpace" * * @return {Boolean} Whether wrapping is enabled or disabled. */ getWrap : function() { if (this.__type === "textarea") { return this._getProperty("wrap"); } else { throw new Error("Text wrapping is only support by textareas!"); } } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) ====================================================================== This class contains code based on the following work: * jQuery http://jquery.com Version 1.3.1 Copyright: 2009 John Resig License: MIT: http://www.opensource.org/licenses/mit-license.php ************************************************************************ */ /* ************************************************************************ #require(qx.lang.Array#contains) ************************************************************************ */ /** * Cross browser abstractions to work with input elements. */ qx.Bootstrap.define("qx.bom.Input", { /* ***************************************************************************** STATICS ***************************************************************************** */ statics : { /** {Map} Internal data structures with all supported input types */ __types : { text : 1, textarea : 1, select : 1, checkbox : 1, radio : 1, password : 1, hidden : 1, submit : 1, image : 1, file : 1, search : 1, reset : 1, button : 1 }, /** * Creates an DOM input/textarea/select element. * * Attributes may be given directly with this call. This is critical * for some attributes e.g. name, type, ... in many clients. * * Note: <code>select</code> and <code>textarea</code> elements are created * using the identically named <code>type</code>. * * @param type {String} Any valid type for HTML, <code>select</code> * and <code>textarea</code> * @param attributes {Map} Map of attributes to apply * @param win {Window} Window to create the element for * @return {Element} The created input node */ create : function(type, attributes, win) { if (qx.core.Environment.get("qx.debug")) { qx.core.Assert.assertKeyInMap(type, this.__types, "Unsupported input type."); } // Work on a copy to not modify given attributes map var attributes = attributes ? qx.lang.Object.clone(attributes) : {}; var tag; if (type === "textarea" || type === "select") { tag = type; } else { tag = "input"; attributes.type = type; } return qx.dom.Element.create(tag, attributes, win); }, /** * Applies the given value to the element. * * Normally the value is given as a string/number value and applied * to the field content (textfield, textarea) or used to * detect whether the field is checked (checkbox, radiobutton). * * Supports array values for selectboxes (multiple-selection) * and checkboxes or radiobuttons (for convenience). * * Please note: To modify the value attribute of a checkbox or * radiobutton use {@link qx.bom.element.Attribute#set} instead. * * @param element {Element} element to update * @param value {String|Number|Array} the value to apply */ setValue : function(element, value) { var tag = element.nodeName.toLowerCase(); var type = element.type; var Array = qx.lang.Array; var Type = qx.lang.Type; if (typeof value === "number") { value += ""; } if ((type === "checkbox" || type === "radio")) { if (Type.isArray(value)) { element.checked = Array.contains(value, element.value); } else { element.checked = element.value == value; } } else if (tag === "select") { var isArray = Type.isArray(value); var options = element.options; var subel, subval; for (var i=0, l=options.length; i<l; i++) { subel = options[i]; subval = subel.getAttribute("value"); if (subval == null) { subval = subel.text; } subel.selected = isArray ? Array.contains(value, subval) : value == subval; } if (isArray && value.length == 0) { element.selectedIndex = -1; } } else if ((type === "text" || type === "textarea") && (qx.core.Environment.get("engine.name") == "mshtml")) { // These flags are required to detect self-made property-change // events during value modification. They are used by the Input // event handler to filter events. element.$$inValueSet = true; element.value = value; element.$$inValueSet = null; } else { element.value = value; } }, /** * Returns the currently configured value. * * Works with simple input fields as well as with * select boxes or option elements. * * Returns an array in cases of multi-selection in * select boxes but in all other cases a string. * * @param element {Element} DOM element to query * @return {String|Array} The value of the given element */ getValue : function(element) { var tag = element.nodeName.toLowerCase(); if (tag === "option") { return (element.attributes.value || {}).specified ? element.value : element.text; } if (tag === "select") { var index = element.selectedIndex; // Nothing was selected if (index < 0) { return null; } var values = []; var options = element.options; var one = element.type == "select-one"; var clazz = qx.bom.Input; var value; // Loop through all the selected options for (var i=one ? index : 0, max=one ? index+1 : options.length; i<max; i++) { var option = options[i]; if (option.selected) { // Get the specifc value for the option value = clazz.getValue(option); // We don't need an array for one selects if (one) { return value; } // Multi-Selects return an array values.push(value); } } return values; } else { return (element.value || "").replace(/\r/g, ""); } }, /** * Sets the text wrap behaviour of a text area element. * This property uses the attribute "wrap" respectively * the style property "whiteSpace" * * @signature function(element, wrap) * @param element {Element} DOM element to modify * @param wrap {Boolean} Whether to turn text wrap on or off. */ setWrap : qx.core.Environment.select("engine.name", { "mshtml" : function(element, wrap) { var wrapValue = wrap ? "soft" : "off"; // Explicitly set overflow-y CSS property to auto when wrapped, // allowing the vertical scroll-bar to appear if necessary var styleValue = wrap ? "auto" : ""; element.wrap = wrapValue; element.style.overflowY = styleValue; }, "gecko|webkit" : function(element, wrap) { var wrapValue = wrap ? "soft" : "off"; var styleValue = wrap ? "" : "auto"; element.setAttribute("wrap", wrapValue); element.style.overflow = styleValue; }, "default" : function(element, wrap) { element.style.whiteSpace = wrap ? "normal" : "nowrap"; } }) } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) * Fabian Jakobs (fjakobs) * Adrian Olaru (adrianolaru) ************************************************************************ */ /** * The TextField is a single-line text input field. */ qx.Class.define("qx.ui.form.TextField", { extend : qx.ui.form.AbstractField, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { // overridden appearance : { refine : true, init : "textfield" }, // overridden allowGrowY : { refine : true, init : false }, // overridden allowShrinkY : { refine : true, init : false } }, members : { // overridden _renderContentElement : function(innerHeight, element) { if ((qx.core.Environment.get("engine.name") == "mshtml") && (parseInt(qx.core.Environment.get("engine.version"), 10) < 9 || qx.core.Environment.get("browser.documentmode") < 9)) { element.setStyles({ "line-height" : innerHeight + 'px' }); } } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) * Martin Wittemann (martinwittemann) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * The RepeatButton is a special button, which fires repeatedly {@link #execute} * events, while the mouse button is pressed on the button. The initial delay * and the interval time can be set using the properties {@link #firstInterval} * and {@link #interval}. The {@link #execute} events will be fired in a shorter * amount of time if the mouse button is hold, until the min {@link #minTimer} * is reached. The {@link #timerDecrease} property sets the amount of milliseconds * which will decreased after every firing. * * <pre class='javascript'> * var button = new qx.ui.form.RepeatButton("Hello World"); * * button.addListener("execute", function(e) { * alert("Button is executed"); * }, this); * * this.getRoot.add(button); * </pre> * * This example creates a button with the label "Hello World" and attaches an * event listener to the {@link #execute} event. * * *External Documentation* * * <a href='http://manual.qooxdoo.org/${qxversion}/pages/widget/repeatbutton.html' target='_blank'> * Documentation of this widget in the qooxdoo manual.</a> */ qx.Class.define("qx.ui.form.RepeatButton", { extend : qx.ui.form.Button, /** * @param label {String} Label to use * @param icon {String?null} Icon to use */ construct : function(label, icon) { this.base(arguments, label, icon); // create the timer and add the listener this.__timer = new qx.event.AcceleratingTimer(); this.__timer.addListener("interval", this._onInterval, this); }, events : { /** * This event gets dispatched with every interval. The timer gets executed * as long as the user holds down the mouse button. */ "execute" : "qx.event.type.Event", /** * This event gets dispatched when the button is pressed. */ "press" : "qx.event.type.Event", /** * This event gets dispatched when the button is released. */ "release" : "qx.event.type.Event" }, properties : { /** * Interval used after the first run of the timer. Usually a smaller value * than the "firstInterval" property value to get a faster reaction. */ interval : { check : "Integer", init : 100 }, /** * Interval used for the first run of the timer. Usually a greater value * than the "interval" property value to a little delayed reaction at the first * time. */ firstInterval : { check : "Integer", init : 500 }, /** This configures the minimum value for the timer interval. */ minTimer : { check : "Integer", init : 20 }, /** Decrease of the timer on each interval (for the next interval) until minTimer reached. */ timerDecrease : { check : "Integer", init : 2 } }, members : { __executed : null, __timer : null, /** * Calling this function is like a click from the user on the * button with all consequences. * <span style='color: red'>Be sure to call the {@link #release} function.</span> * * @return {void} */ press : function() { // only if the button is enabled if (this.isEnabled()) { // if the state pressed must be applied (first call) if (!this.hasState("pressed")) { // start the timer this.__startInternalTimer(); } // set the states this.removeState("abandoned"); this.addState("pressed"); } }, /** * Calling this function is like a release from the user on the * button with all consequences. * Usually the {@link #release} function will be called before the call of * this function. * * @param fireExecuteEvent {Boolean?true} flag which signals, if an event should be fired * @return {void} */ release : function(fireExecuteEvent) { // only if the button is enabled if (!this.isEnabled()) { return; } // only if the button is pressed if (this.hasState("pressed")) { // if the button has not been executed if (!this.__executed) { this.execute(); } } // remove button states this.removeState("pressed"); this.removeState("abandoned"); // stop the repeat timer and therefore the execution this.__stopInternalTimer(); }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // overridden _applyEnabled : function(value, old) { this.base(arguments, value, old); if (!value) { // remove button states this.removeState("pressed"); this.removeState("abandoned"); // stop the repeat timer and therefore the execution this.__stopInternalTimer(); } }, /* --------------------------------------------------------------------------- EVENT HANDLER --------------------------------------------------------------------------- */ /** * Listener method for "mouseover" event * <ul> * <li>Adds state "hovered"</li> * <li>Removes "abandoned" and adds "pressed" state (if "abandoned" state is set)</li> * </ul> * * @param e {Event} Mouse event * @return {void} */ _onMouseOver : function(e) { if (!this.isEnabled() || e.getTarget() !== this) { return; } if (this.hasState("abandoned")) { this.removeState("abandoned"); this.addState("pressed"); this.__timer.start(); } this.addState("hovered"); }, /** * Listener method for "mouseout" event * <ul> * <li>Removes "hovered" state</li> * <li>Adds "abandoned" and removes "pressed" state (if "pressed" state is set)</li> * </ul> * * @param e {Event} Mouse event * @return {void} */ _onMouseOut : function(e) { if (!this.isEnabled() || e.getTarget() !== this) { return; } this.removeState("hovered"); if (this.hasState("pressed")) { this.removeState("pressed"); this.addState("abandoned"); this.__timer.stop(); } }, /** * Callback method for the "mouseDown" method. * * Sets the interval of the timer (value of firstInterval property) and * starts the timer. Additionally removes the state "abandoned" and adds the * state "pressed". * * @param e {qx.event.type.Mouse} mouseDown event * @return {void} */ _onMouseDown : function(e) { if (!e.isLeftPressed()) { return; } // Activate capturing if the button get a mouseout while // the button is pressed. this.capture(); this.__startInternalTimer(); e.stopPropagation(); }, /** * Callback method for the "mouseUp" event. * * Handles the case that the user is releasing the mouse button * before the timer interval method got executed. This way the * "execute" method get executed at least one time. * * @param e {qx.event.type.Mouse} mouseUp event * @return {void} */ _onMouseUp : function(e) { this.releaseCapture(); if (!this.hasState("abandoned")) { this.addState("hovered"); if (this.hasState("pressed") && !this.__executed) { this.execute(); } } this.__stopInternalTimer(); e.stopPropagation(); }, /** * Listener method for "keyup" event. * * Removes "abandoned" and "pressed" state (if "pressed" state is set) * for the keys "Enter" or "Space" and stopps the internal timer * (same like mouse up). * * @param e {Event} Key event * @return {void} */ _onKeyUp : function(e) { switch(e.getKeyIdentifier()) { case "Enter": case "Space": if (this.hasState("pressed")) { if (!this.__executed) { this.execute(); } this.removeState("pressed"); this.removeState("abandoned"); e.stopPropagation(); this.__stopInternalTimer(); } } }, /** * Listener method for "keydown" event. * * Removes "abandoned" and adds "pressed" state * for the keys "Enter" or "Space". It also starts * the internal timer (same like mousedown). * * @param e {Event} Key event * @return {void} */ _onKeyDown : function(e) { switch(e.getKeyIdentifier()) { case "Enter": case "Space": this.removeState("abandoned"); this.addState("pressed"); e.stopPropagation(); this.__startInternalTimer(); } }, /** * Callback for the interval event. * * Stops the timer and starts it with a new interval * (value of the "interval" property - value of the "timerDecrease" property). * Dispatches the "execute" event. * * @param e {qx.event.type.Event} interval event * @return {void} */ _onInterval : function(e) { this.__executed = true; this.fireEvent("execute"); }, /* --------------------------------------------------------------------------- INTERNAL TIMER --------------------------------------------------------------------------- */ /** * Starts the internal timer which causes firing of execution * events in an interval. It also presses the button. * * @return {void} */ __startInternalTimer : function() { this.fireEvent("press"); this.__executed = false; this.__timer.set({ interval: this.getInterval(), firstInterval: this.getFirstInterval(), minimum: this.getMinTimer(), decrease: this.getTimerDecrease() }).start(); this.removeState("abandoned"); this.addState("pressed"); }, /** * Stops the internal timer and releases the button. * * @return {void} */ __stopInternalTimer : function() { this.fireEvent("release"); this.__timer.stop(); this.removeState("abandoned"); this.removeState("pressed"); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this._disposeObjects("__timer"); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * Timer, which accelerates after each interval. The initial delay and the * interval time can be set using the properties {@link #firstInterval} * and {@link #interval}. The {@link #interval} events will be fired with * decreasing interval times while the timer is running, until the {@link #minimum} * is reached. The {@link #decrease} property sets the amount of milliseconds * which will decreased after every firing. * * This class is e.g. used in the {@link qx.ui.form.RepeatButton} and * {@link qx.ui.form.HoverButton} widgets. */ qx.Class.define("qx.event.AcceleratingTimer", { extend : qx.core.Object, construct : function() { this.base(arguments); this.__timer = new qx.event.Timer(this.getInterval()); this.__timer.addListener("interval", this._onInterval, this); }, events : { /** This event if fired each time the interval time has elapsed */ "interval" : "qx.event.type.Event" }, properties : { /** * Interval used after the first run of the timer. Usually a smaller value * than the "firstInterval" property value to get a faster reaction. */ interval : { check : "Integer", init : 100 }, /** * Interval used for the first run of the timer. Usually a greater value * than the "interval" property value to a little delayed reaction at the first * time. */ firstInterval : { check : "Integer", init : 500 }, /** This configures the minimum value for the timer interval. */ minimum : { check : "Integer", init : 20 }, /** Decrease of the timer on each interval (for the next interval) until minTimer reached. */ decrease : { check : "Integer", init : 2 } }, members : { __timer : null, __currentInterval : null, /** * Reset and start the timer. */ start : function() { this.__timer.setInterval(this.getFirstInterval()); this.__timer.start(); }, /** * Stop the timer */ stop : function() { this.__timer.stop(); this.__currentInterval = null; }, /** * Interval event handler */ _onInterval : function() { this.__timer.stop(); if (this.__currentInterval == null) { this.__currentInterval = this.getInterval(); } this.__currentInterval = Math.max( this.getMinimum(), this.__currentInterval - this.getDecrease() ); this.__timer.setInterval(this.__currentInterval); this.__timer.start(); this.fireEvent("interval"); } }, destruct : function() { this._disposeObjects("__timer"); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) * Fabian Jakobs (fjakobs) ************************************************************************ */ /* #cldr */ /** * Provides information about locale-dependent number formatting (like the decimal * separator). */ qx.Class.define("qx.locale.Number", { statics : { /** * Get decimal separator for number formatting * * @param locale {String} optional locale to be used * @return {String} decimal separator. */ getDecimalSeparator : function(locale) { return qx.locale.Manager.getInstance().localize("cldr_number_decimal_separator", [], locale) }, /** * Get thousand grouping separator for number formatting * * @param locale {String} optional locale to be used * @return {String} group separator. */ getGroupSeparator : function(locale) { return qx.locale.Manager.getInstance().localize("cldr_number_group_separator", [], locale) }, /** * Get percent format string * * @param locale {String} optional locale to be used * @return {String} percent format string. */ getPercentFormat : function(locale) { return qx.locale.Manager.getInstance().localize("cldr_number_percent_format", [], locale) } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * Each object, which should be managed by a {@link RadioGroup} have to * implement this interface. */ qx.Interface.define("qx.ui.form.IRadioItem", { /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fired when the item was checked or unchecked */ "changeValue" : "qx.event.type.Data" }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** * Set whether the item is checked * * @param value {Boolean} whether the item should be checked */ setValue : function(value) {}, /** * Get whether the item is checked * * @return {Boolean} whether the item it checked */ getValue : function() {}, /** * Set the radiogroup, which manages this item * * @param value {qx.ui.form.RadioGroup} The radiogroup, which should * manage the item. */ setGroup : function(value) { this.assertInstance(value, qx.ui.form.RadioGroup); }, /** * Get the radiogroup, which manages this item * * @return {qx.ui.form.RadioGroup} The radiogroup, which manages the item. */ getGroup : function() {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Christian Hagendorn (chris_schmidt) ************************************************************************ */ /** * This mixin links all methods to manage the single selection. * * The class which includes the mixin has to implements two methods: * * <ul> * <li><code>_getItems</code>, this method has to return a <code>Array</code> * of <code>qx.ui.core.Widget</code> that should be managed from the manager. * </li> * <li><code>_isAllowEmptySelection</code>, this method has to return a * <code>Boolean</code> value for allowing empty selection or not. * </li> * </ul> */ qx.Mixin.define("qx.ui.core.MSingleSelectionHandling", { /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fires after the selection was modified */ "changeSelection" : "qx.event.type.Data" }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** {qx.ui.core.SingleSelectionManager} the single selection manager */ __manager : null, /* --------------------------------------------------------------------------- PUBLIC API --------------------------------------------------------------------------- */ /** * Returns an array of currently selected items. * * Note: The result is only a set of selected items, so the order can * differ from the sequence in which the items were added. * * @return {qx.ui.core.Widget[]} List of items. */ getSelection : function() { var selected = this.__getManager().getSelected(); if (selected) { return [selected]; } else { return []; } }, /** * Replaces current selection with the given items. * * @param items {qx.ui.core.Widget[]} Items to select. * @throws an exception if one of the items is not a child element and if * items contains more than one elements. */ setSelection : function(items) { switch(items.length) { case 0: this.resetSelection(); break; case 1: this.__getManager().setSelected(items[0]); break; default: throw new Error("Could only select one item, but the selection" + " array contains " + items.length + " items!"); } }, /** * Clears the whole selection at once. */ resetSelection : function() { this.__getManager().resetSelected(); }, /** * Detects whether the given item is currently selected. * * @param item {qx.ui.core.Widget} Any valid selectable item. * @return {Boolean} Whether the item is selected. * @throws an exception if one of the items is not a child element. */ isSelected : function(item) { return this.__getManager().isSelected(item); }, /** * Whether the selection is empty. * * @return {Boolean} Whether the selection is empty. */ isSelectionEmpty : function() { return this.__getManager().isSelectionEmpty(); }, /** * Returns all elements which are selectable. * * @param all {boolean} true for all selectables, false for the * selectables the user can interactively select * @return {qx.ui.core.Widget[]} The contained items. */ getSelectables: function(all) { return this.__getManager().getSelectables(all); }, /* --------------------------------------------------------------------------- EVENT HANDLER --------------------------------------------------------------------------- */ /** * Event listener for <code>changeSelected</code> event on single * selection manager. * * @param e {qx.event.type.Data} Data event. */ _onChangeSelected : function(e) { var newValue = e.getData(); var oldVlaue = e.getOldData(); newValue == null ? newValue = [] : newValue = [newValue]; oldVlaue == null ? oldVlaue = [] : oldVlaue = [oldVlaue]; this.fireDataEvent("changeSelection", newValue, oldVlaue); }, /** * Return the selection manager if it is already exists, otherwise creates * the manager. * * @return {qx.ui.core.SingleSelectionManager} Single selection manager. */ __getManager : function() { if (this.__manager == null) { var that = this; this.__manager = new qx.ui.core.SingleSelectionManager( { getItems : function() { return that._getItems(); }, isItemSelectable : function(item) { if (that._isItemSelectable) { return that._isItemSelectable(item); } else { return item.isVisible(); } } }); this.__manager.addListener("changeSelected", this._onChangeSelected, this); } this.__manager.setAllowEmptySelection(this._isAllowEmptySelection()); return this.__manager; } }, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ destruct : function() { this._disposeObjects("__manager"); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Christian Hagendorn (chris_schmidt) ************************************************************************ */ /** * Responsible for the single selection management. * * The class manage a list of {@link qx.ui.core.Widget} which are returned from * {@link qx.ui.core.ISingleSelectionProvider#getItems}. * * @internal */ qx.Class.define("qx.ui.core.SingleSelectionManager", { extend : qx.core.Object, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * Construct the single selection manager. * * @param selectionProvider {qx.ui.core.ISingleSelectionProvider} The provider * for selection. */ construct : function(selectionProvider) { this.base(arguments); if (qx.core.Environment.get("qx.debug")) { qx.core.Assert.assertInterface(selectionProvider, qx.ui.core.ISingleSelectionProvider, "Invalid selectionProvider!"); } this.__selectionProvider = selectionProvider; }, /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fires after the selection was modified */ "changeSelected" : "qx.event.type.Data" }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * If the value is <code>true</code> the manager allows an empty selection, * otherwise the first selectable element returned from the * <code>qx.ui.core.ISingleSelectionProvider</code> will be selected. */ allowEmptySelection : { check : "Boolean", init : true, apply : "__applyAllowEmptySelection" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** {qx.ui.core.Widget} The selected widget. */ __selected : null, /** {qx.ui.core.ISingleSelectionProvider} The provider for selection management */ __selectionProvider : null, /* --------------------------------------------------------------------------- PUBLIC API --------------------------------------------------------------------------- */ /** * Returns the current selected element. * * @return {qx.ui.core.Widget | null} The current selected widget or * <code>null</code> if the selection is empty. */ getSelected : function() { return this.__selected; }, /** * Selects the passed element. * * @param item {qx.ui.core.Widget} Element to select. * @throws Error if the element is not a child element. */ setSelected : function(item) { if (!this.__isChildElement(item)) { throw new Error("Could not select " + item + ", because it is not a child element!"); } this.__setSelected(item); }, /** * Reset the current selection. If {@link #allowEmptySelection} is set to * <code>true</code> the first element will be selected. */ resetSelected : function(){ this.__setSelected(null); }, /** * Return <code>true</code> if the passed element is selected. * * @param item {qx.ui.core.Widget} Element to check if selected. * @return {Boolean} <code>true</code> if passed element is selected, * <code>false</code> otherwise. * @throws Error if the element is not a child element. */ isSelected : function(item) { if (!this.__isChildElement(item)) { throw new Error("Could not check if " + item + " is selected," + " because it is not a child element!"); } return this.__selected === item; }, /** * Returns <code>true</code> if selection is empty. * * @return {Boolean} <code>true</code> if selection is empty, * <code>false</code> otherwise. */ isSelectionEmpty : function() { return this.__selected == null; }, /** * Returns all elements which are selectable. * * @param all {boolean} true for all selectables, false for the * selectables the user can interactively select * @return {qx.ui.core.Widget[]} The contained items. */ getSelectables : function(all) { var items = this.__selectionProvider.getItems(); var result = []; for (var i = 0; i < items.length; i++) { if (this.__selectionProvider.isItemSelectable(items[i])) { result.push(items[i]); } } // in case of an user selecable list, remove the enabled items if (!all) { for (var i = result.length -1; i >= 0; i--) { if (!result[i].getEnabled()) { result.splice(i, 1); } }; } return result; }, /* --------------------------------------------------------------------------- APPLY METHODS --------------------------------------------------------------------------- */ // apply method __applyAllowEmptySelection : function(value, old) { if (!value) { this.__setSelected(this.__selected); } }, /* --------------------------------------------------------------------------- HELPERS --------------------------------------------------------------------------- */ /** * Set selected element. * * If passes value is <code>null</code>, the selection will be reseted. * * @param item {qx.ui.core.Widget | null} element to select, or * <code>null</code> to reset selection. */ __setSelected : function(item) { var oldSelected = this.__selected; var newSelected = item; if (newSelected != null && oldSelected === newSelected) { return; } if (!this.isAllowEmptySelection() && newSelected == null) { var firstElement = this.getSelectables(true)[0]; if (firstElement) { newSelected = firstElement; } } this.__selected = newSelected; this.fireDataEvent("changeSelected", newSelected, oldSelected); }, /** * Checks if passed element is a child element. * * @param item {qx.ui.core.Widget} Element to check if child element. * @return {Boolean} <code>true</code> if element is child element, * <code>false</code> otherwise. */ __isChildElement : function(item) { var items = this.__selectionProvider.getItems(); for (var i = 0; i < items.length; i++) { if (items[i] === item) { return true; } } return false; } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { if (this.__selectionProvider.toHashCode) { this._disposeObjects("__selectionProvider"); } else { this.__selectionProvider = null; } this._disposeObjects("__selected"); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Christian Hagendorn (chris_schmidt) ************************************************************************ */ /** * Defines the callback for the single selection manager. * * @internal */ qx.Interface.define("qx.ui.core.ISingleSelectionProvider", { /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** * Returns the elements which are part of the selection. * * @return {qx.ui.core.Widget[]} The widgets for the selection. */ getItems: function() {}, /** * Returns whether the given item is selectable. * * @param item {qx.ui.core.Widget} The item to be checked * @return {Boolean} Whether the given item is selectable */ isItemSelectable : function(item) {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * This mixin offers the selection of the model properties. * It can only be included if the object including it implements the * {@link qx.ui.core.ISingleSelection} interface and the selectables implement * the {@link qx.ui.form.IModel} interface. */ qx.Mixin.define("qx.ui.form.MModelSelection", { construct : function() { // create the selection array this.__modelSelection = new qx.data.Array(); // listen to the changes this.__modelSelection.addListener("change", this.__onModelSelectionArrayChange, this); this.addListener("changeSelection", this.__onModelSelectionChange, this); }, events : { /** * Pseudo event. It will never be fired because the array itself can not * be changed. But the event description is needed for the data binding. */ changeModelSelection : "qx.event.type.Data" }, members : { __modelSelection : null, __inSelectionChange : false, /** * Handler for the selection change of the including class e.g. SelectBox, * List, ... * It sets the new modelSelection via {@link #setModelSelection}. */ __onModelSelectionChange : function() { if (this.__inSelectionChange) { return; } var data = this.getSelection(); // create the array with the modes inside var modelSelection = []; for (var i = 0; i < data.length; i++) { var item = data[i]; // fallback if getModel is not implemented var model = item.getModel ? item.getModel() : null; if (model !== null) { modelSelection.push(model); } }; // only change the selection if you are sure that its correct [BUG #3748] if (modelSelection.length === data.length) { try { this.setModelSelection(modelSelection); } catch (e) { throw new Error( "Could not set the model selection. Maybe your models are not unique?" ); } } }, /** * Listener for the change of the internal model selection data array. */ __onModelSelectionArrayChange : function() { this.__inSelectionChange = true; var selectables = this.getSelectables(true); var itemSelection = []; var modelSelection = this.__modelSelection.toArray(); for (var i = 0; i < modelSelection.length; i++) { var model = modelSelection[i]; for (var j = 0; j < selectables.length; j++) { var selectable = selectables[j]; // fallback if getModel is not implemented var selectableModel = selectable.getModel ? selectable.getModel() : null; if (model === selectableModel) { itemSelection.push(selectable); break; } } } this.setSelection(itemSelection); this.__inSelectionChange = false; // check if the setting has worked var currentSelection = this.getSelection(); if (!qx.lang.Array.equals(currentSelection, itemSelection)) { // if not, set the actual selection this.__onModelSelectionChange(); } }, /** * Returns always an array of the models of the selected items. If no * item is selected or no model is given, the array will be empty. * * *CAREFUL!* The model selection can only work if every item item in the * selection providing widget has a model property! * * @return {qx.data.Array} An array of the models of the selected items. */ getModelSelection : function() { return this.__modelSelection; }, /** * Takes the given models in the array and searches for the corresponding * selectables. If an selectable does have that model attached, it will be * selected. * * *Attention:* This method can have a time complexity of O(n^2)! * * *CAREFUL!* The model selection can only work if every item item in the * selection providing widget has a model property! * * @param modelSelection {Array} An array of models, which should be * selected. */ setModelSelection : function(modelSelection) { // check for null values if (!modelSelection) { this.__modelSelection.removeAll(); return; } if (qx.core.Environment.get("qx.debug")) { this.assertArray(modelSelection, "Please use an array as parameter."); } // add the first two parameter modelSelection.unshift(this.__modelSelection.getLength()); // remove index modelSelection.unshift(0); // start index var returnArray = this.__modelSelection.splice.apply(this.__modelSelection, modelSelection); returnArray.dispose(); } }, destruct : function() { this._disposeObjects("__modelSelection"); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * This interface should be used in all objects managing a set of items * implementing {@link qx.ui.form.IModel}. */ qx.Interface.define("qx.ui.form.IModelSelection", { /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** * Tries to set the selection using the given array containing the * representative models for the selectables. * * @param value {Array} An array of models. */ setModelSelection : function(value) {}, /** * Returns an array of the selected models. * * @return {Array} An array containing the models of the currently selected * items. */ getModelSelection : function() {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) * Christian Hagendorn (chris_schmidt) * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * The radio group handles a collection of items from which only one item * can be selected. Selection another item will deselect the previously selected * item. * * This class is e.g. used to create radio groups or {@link qx.ui.form.RadioButton} * or {@link qx.ui.toolbar.RadioButton} instances. * * We also offer a widget for the same purpose which uses this class. So if * you like to act with a widget instead of a pure logic coupling of the * widgets, take a look at the {@link qx.ui.form.RadioButtonGroup} widget. */ qx.Class.define("qx.ui.form.RadioGroup", { extend : qx.core.Object, implement : [ qx.ui.core.ISingleSelection, qx.ui.form.IForm, qx.ui.form.IModelSelection ], include : [ qx.ui.core.MSingleSelectionHandling, qx.ui.form.MModelSelection ], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param varargs {qx.core.Object} A variable number of items, which are * initially added to the radio group, the first item will be selected. */ construct : function(varargs) { this.base(arguments); // create item array this.__items = []; // add listener before call add!!! this.addListener("changeSelection", this.__onChangeSelection, this); if (varargs != null) { this.add.apply(this, arguments); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * Whether the radio group is enabled */ enabled : { check : "Boolean", apply : "_applyEnabled", event : "changeEnabled", init: true }, /** * Whether the selection should wrap around. This means that the successor of * the last item is the first item. */ wrap : { check : "Boolean", init: true }, /** * If is set to <code>true</code> the selection could be empty, * otherwise is always one <code>RadioButton</code> selected. */ allowEmptySelection : { check : "Boolean", init : false, apply : "_applyAllowEmptySelection" }, /** * Flag signaling if the group at all is valid. All children will have the * same state. */ valid : { check : "Boolean", init : true, apply : "_applyValid", event : "changeValid" }, /** * Flag signaling if the group is required. */ required : { check : "Boolean", init : false, event : "changeRequired" }, /** * Message which is shown in an invalid tooltip. */ invalidMessage : { check : "String", init: "", event : "changeInvalidMessage", apply : "_applyInvalidMessage" }, /** * Message which is shown in an invalid tooltip if the {@link #required} is * set to true. */ requiredInvalidMessage : { check : "String", nullable : true, event : "changeInvalidMessage" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** {qx.ui.form.IRadioItem[]} The items of the radio group */ __items : null, /* --------------------------------------------------------------------------- UTILITIES --------------------------------------------------------------------------- */ /** * Get all managed items * * @return {qx.ui.form.IRadioItem[]} All managed items. */ getItems : function() { return this.__items; }, /* --------------------------------------------------------------------------- REGISTRY --------------------------------------------------------------------------- */ /** * Add the passed items to the radio group. * * @param varargs {qx.ui.form.IRadioItem} A variable number of items to add. */ add : function(varargs) { var items = this.__items; var item; for (var i=0, l=arguments.length; i<l; i++) { item = arguments[i]; if (qx.lang.Array.contains(items, item)) { continue; } // Register listeners item.addListener("changeValue", this._onItemChangeChecked, this); // Push RadioButton to array items.push(item); // Inform radio button about new group item.setGroup(this); // Need to update internal value? if (item.getValue()) { this.setSelection([item]); } } // Select first item when only one is registered if (!this.isAllowEmptySelection() && items.length > 0 && !this.getSelection()[0]) { this.setSelection([items[0]]); } }, /** * Remove an item from the radio group. * * @param item {qx.ui.form.IRadioItem} The item to remove. */ remove : function(item) { var items = this.__items; if (qx.lang.Array.contains(items, item)) { // Remove RadioButton from array qx.lang.Array.remove(items, item); // Inform radio button about new group if (item.getGroup() === this) { item.resetGroup(); } // Deregister listeners item.removeListener("changeValue", this._onItemChangeChecked, this); // if the radio was checked, set internal selection to null if (item.getValue()) { this.resetSelection(); } } }, /** * Returns an array containing the group's items. * * @return {qx.ui.form.IRadioItem[]} The item array */ getChildren : function() { return this.__items; }, /* --------------------------------------------------------------------------- LISTENER FOR ITEM CHANGES --------------------------------------------------------------------------- */ /** * Event listener for <code>changeValue</code> event of every managed item. * * @param e {qx.event.type.Data} Data event */ _onItemChangeChecked : function(e) { var item = e.getTarget(); if (item.getValue()) { this.setSelection([item]); } else if (this.getSelection()[0] == item) { this.resetSelection(); } }, /* --------------------------------------------------------------------------- APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyInvalidMessage : function(value, old) { for (var i = 0; i < this.__items.length; i++) { this.__items[i].setInvalidMessage(value); } }, // property apply _applyValid: function(value, old) { for (var i = 0; i < this.__items.length; i++) { this.__items[i].setValid(value); } }, // property apply _applyEnabled : function(value, old) { var items = this.__items; if (value == null) { for (var i=0, l=items.length; i<l; i++) { items[i].resetEnabled(); } } else { for (var i=0, l=items.length; i<l; i++) { items[i].setEnabled(value); } } }, // property apply _applyAllowEmptySelection : function(value, old) { if (!value && this.isSelectionEmpty()) { this.resetSelection(); } }, /* --------------------------------------------------------------------------- SELECTION --------------------------------------------------------------------------- */ /** * Select the item following the given item. */ selectNext : function() { var item = this.getSelection()[0]; var items = this.__items; var index = items.indexOf(item); if (index == -1) { return; } var i = 0; var length = items.length; // Find next enabled item if (this.getWrap()) { index = (index + 1) % length; } else { index = Math.min(index + 1, length - 1); } while (i < length && !items[index].getEnabled()) { index = (index + 1) % length; i++; } this.setSelection([items[index]]); }, /** * Select the item previous the given item. */ selectPrevious : function() { var item = this.getSelection()[0]; var items = this.__items; var index = items.indexOf(item); if (index == -1) { return; } var i = 0; var length = items.length; // Find previous enabled item if (this.getWrap()) { index = (index - 1 + length) % length; } else { index = Math.max(index - 1, 0); } while (i < length && !items[index].getEnabled()) { index = (index - 1 + length) % length; i++; } this.setSelection([items[index]]); }, /* --------------------------------------------------------------------------- HELPER METHODS FOR SELECTION API --------------------------------------------------------------------------- */ /** * Returns the items for the selection. * * @return {qx.ui.form.IRadioItem[]} Items to select. */ _getItems : function() { return this.getItems(); }, /** * Returns if the selection could be empty or not. * * @return {Boolean} <code>true</code> If selection could be empty, * <code>false</code> otherwise. */ _isAllowEmptySelection: function() { return this.isAllowEmptySelection(); }, /** * Returns whether the item is selectable. In opposite to the default * implementation (which checks for visible items) every radio button * which is part of the group is selected even if it is currently not visible. * * @param item {qx.ui.form.IRadioItem} The item to check if its selectable. * @return {Boolean} <code>true</code> if the item is part of the radio group * <code>false</code> otherwise. */ _isItemSelectable : function(item) { return this.__items.indexOf(item) != -1; }, /** * Event handler for <code>changeSelection</code>. * * @param e {qx.event.type.Data} Data event. */ __onChangeSelection : function(e) { var value = e.getData()[0]; var old = e.getOldData()[0]; if (old) { old.setValue(false); } if (value) { value.setValue(true); } } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this._disposeArray("__items"); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * A toggle Button widget * * If the user presses the button by clicking on it pressing the enter or * space key, the button toggles between the pressed an not pressed states. * There is no execute event, only a {@link qx.ui.form.ToggleButton#changeValue} * event. */ qx.Class.define("qx.ui.form.ToggleButton", { extend : qx.ui.basic.Atom, include : [ qx.ui.core.MExecutable ], implement : [ qx.ui.form.IBooleanForm, qx.ui.form.IExecutable, qx.ui.form.IRadioItem ], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * Creates a ToggleButton. * * @param label {String} The text on the button. * @param icon {String} An URI to the icon of the button. */ construct : function(label, icon) { this.base(arguments, label, icon); // register mouse events this.addListener("mouseover", this._onMouseOver); this.addListener("mouseout", this._onMouseOut); this.addListener("mousedown", this._onMouseDown); this.addListener("mouseup", this._onMouseUp); // register keyboard events this.addListener("keydown", this._onKeyDown); this.addListener("keyup", this._onKeyUp); // register execute event this.addListener("execute", this._onExecute, this); }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties: { // overridden appearance: { refine: true, init: "button" }, // overridden focusable : { refine : true, init : true }, /** The value of the widget. True, if the widget is checked. */ value : { check : "Boolean", nullable : true, event : "changeValue", apply : "_applyValue", init : false }, /** The assigned qx.ui.form.RadioGroup which handles the switching between registered buttons. */ group : { check : "qx.ui.form.RadioGroup", nullable : true, apply : "_applyGroup" }, /** * Whether the button has a third state. Use this for tri-state checkboxes. * * When enabled, the value null of the property value stands for "undetermined", * while true is mapped to "enabled" and false to "disabled" as usual. Note * that the value property is set to false initially. * */ triState : { check : "Boolean", apply : "_applyTriState", nullable : true, init : null } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** The assigned {@link qx.ui.form.RadioGroup} which handles the switching between registered buttons */ _applyGroup : function(value, old) { if (old) { old.remove(this); } if (value) { value.add(this); } }, /** * Changes the state of the button dependent on the checked value. * * @param value {Boolean} Current value * @param old {Boolean} Previous value */ _applyValue : function(value, old) { value ? this.addState("checked") : this.removeState("checked"); if (this.isTriState()) { if (value === null) { this.addState("undetermined"); } else if (old === null) { this.removeState("undetermined"); } } }, /** * Apply value property when triState property is modified. * * @param value {Boolean} Current value * @param old {Boolean} Previous value */ _applyTriState : function(value, old) { this._applyValue(this.getValue()); }, /** * Handler for the execute event. * * @param e {qx.event.type.Event} The execute event. */ _onExecute : function(e) { this.toggleValue(); }, /** * Listener method for "mouseover" event. * <ul> * <li>Adds state "hovered"</li> * <li>Removes "abandoned" and adds "pressed" state (if "abandoned" state is set)</li> * </ul> * * @param e {Event} Mouse event * @return {void} */ _onMouseOver : function(e) { if (e.getTarget() !== this) { return; } this.addState("hovered"); if (this.hasState("abandoned")) { this.removeState("abandoned"); this.addState("pressed"); } }, /** * Listener method for "mouseout" event. * <ul> * <li>Removes "hovered" state</li> * <li>Adds "abandoned" state (if "pressed" state is set)</li> * <li>Removes "pressed" state (if "pressed" state is set and button is not checked) * </ul> * * @param e {Event} Mouse event * @return {void} */ _onMouseOut : function(e) { if (e.getTarget() !== this) { return; } this.removeState("hovered"); if (this.hasState("pressed")) { if (!this.getValue()) { this.removeState("pressed"); } this.addState("abandoned"); } }, /** * Listener method for "mousedown" event. * <ul> * <li>Activates capturing</li> * <li>Removes "abandoned" state</li> * <li>Adds "pressed" state</li> * </ul> * * @param e {Event} Mouse event * @return {void} */ _onMouseDown : function(e) { if (!e.isLeftPressed()) { return; } // Activate capturing if the button get a mouseout while // the button is pressed. this.capture(); this.removeState("abandoned"); this.addState("pressed"); e.stopPropagation(); }, /** * Listener method for "mouseup" event. * <ul> * <li>Releases capturing</li> * <li>Removes "pressed" state (if not "abandoned" state is set and "pressed" state is set)</li> * <li>Removes "abandoned" state (if set)</li> * <li>Toggles {@link #value} (if state "abandoned" is not set and state "pressed" is set)</li> * </ul> * * @param e {Event} Mouse event * @return {void} */ _onMouseUp : function(e) { this.releaseCapture(); if (this.hasState("abandoned")) { this.removeState("abandoned"); } else if (this.hasState("pressed")) { this.execute(); } this.removeState("pressed"); e.stopPropagation(); }, /** * Listener method for "keydown" event.<br/> * Removes "abandoned" and adds "pressed" state * for the keys "Enter" or "Space" * * @param e {Event} Key event * @return {void} */ _onKeyDown : function(e) { switch(e.getKeyIdentifier()) { case "Enter": case "Space": this.removeState("abandoned"); this.addState("pressed"); e.stopPropagation(); } }, /** * Listener method for "keyup" event.<br/> * Removes "abandoned" and "pressed" state (if "pressed" state is set) * for the keys "Enter" or "Space". It also toggles the {@link #value} property. * * @param e {Event} Key event * @return {void} */ _onKeyUp : function(e) { if (!this.hasState("pressed")) { return; } switch(e.getKeyIdentifier()) { case "Enter": case "Space": this.removeState("abandoned"); this.execute(); this.removeState("pressed"); e.stopPropagation(); } } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Can be included for implementing {@link qx.ui.form.IModel}. It only contains * a nullable property named 'model' with a 'changeModel' event. */ qx.Mixin.define("qx.ui.form.MModelProperty", { properties : { /** * Model property for storing additional information for the including * object. It can act as value property on form items for example. * * Be careful using that property as this is used for the * {@link qx.ui.form.MModelSelection} it has some restrictions: * * * Don't use equal models in one widget using the * {@link qx.ui.form.MModelSelection}. * * * Avoid setting only some model properties if the widgets are added to * a {@link qx.ui.form.MModelSelection} widge. * * Both restrictions result of the fact, that the set models are deputies * for their widget. */ model : { nullable: true, event: "changeModel", dereference : true } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Each object which wants to store data representative for the real item * should implement this interface. */ qx.Interface.define("qx.ui.form.IModel", { /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fired when the model data changes */ "changeModel" : "qx.event.type.Data" }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** * Set the representative data for the item. * * @param value {var} The data. */ setModel : function(value) {}, /** * Returns the representative data for the item * * @return {var} The data. */ getModel : function() {}, /** * Sets the representative data to null. */ resetModel : function() {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) * Andreas Ecker (ecker) ************************************************************************ */ /** * A check box widget with an optional label. */ qx.Class.define("qx.ui.form.CheckBox", { extend : qx.ui.form.ToggleButton, include : [ qx.ui.form.MForm, qx.ui.form.MModelProperty ], implement : [ qx.ui.form.IForm, qx.ui.form.IModel ], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param label {String?null} An optional label for the check box. */ construct : function(label) { if (qx.core.Environment.get("qx.debug")) { this.assertArgumentsCount(arguments, 0, 1); } this.base(arguments, label); // Initialize the checkbox to a valid value (the default is null which // is invalid) this.setValue(false); }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { // overridden appearance : { refine : true, init : "checkbox" }, // overridden allowGrowX : { refine : true, init : false } }, /** * @lint ignoreReferenceField(_forwardStates,_bindableProperties) */ members : { // overridden _forwardStates : { invalid : true, focused : true, undetermined : true, checked : true, hovered : true }, // overridden (from MExecutable to keet the icon out of the binding) _bindableProperties : [ "enabled", "label", "toolTipText", "value", "menu" ] } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * This mixin redirects all children handling methods to a child widget of the * including class. This is e.g. used in {@link qx.ui.window.Window} to add * child widgets directly to the window pane. * * The including class must implement the method <code>getChildrenContainer</code>, * which has to return the widget, to which the child widgets should be added. */ qx.Mixin.define("qx.ui.core.MRemoteChildrenHandling", { /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** * Forward the call with the given function name to the children container * * @param functionName {String} name of the method to forward * @param a1 {var} first argument of the method to call * @param a2 {var} second argument of the method to call * @param a3 {var} third argument of the method to call * @return {var} The return value of the forward method */ __forward : function(functionName, a1, a2, a3) { var container = this.getChildrenContainer(); if (container === this) { functionName = "_" + functionName; } return (container[functionName])(a1, a2, a3); }, /** * Returns the children list * * @return {LayoutItem[]} The children array (Arrays are * reference types, please to not modify them in-place) */ getChildren : function() { return this.__forward("getChildren"); }, /** * Whether the widget contains children. * * @return {Boolean} Returns <code>true</code> when the widget has children. */ hasChildren : function() { return this.__forward("hasChildren"); }, /** * Adds a new child widget. * * The supported keys of the layout options map depend on the layout manager * used to position the widget. The options are documented in the class * documentation of each layout manager {@link qx.ui.layout}. * * @param child {LayoutItem} the item to add. * @param options {Map?null} Optional layout data for item. * @return {Widget} This object (for chaining support) */ add : function(child, options) { return this.__forward("add", child, options); }, /** * Remove the given child item. * * @param child {LayoutItem} the item to remove * @return {Widget} This object (for chaining support) */ remove : function(child) { return this.__forward("remove", child); }, /** * Remove all children. * * @return {void} */ removeAll : function() { return this.__forward("removeAll"); }, /** * Returns the index position of the given item if it is * a child item. Otherwise it returns <code>-1</code>. * * This method works on the widget's children list. Some layout managers * (e.g. {@link qx.ui.layout.HBox}) use the children order as additional * layout information. Other layout manager (e.g. {@link qx.ui.layout.Grid}) * ignore the children order for the layout process. * * @param child {LayoutItem} the item to query for * @return {Integer} The index position or <code>-1</code> when * the given item is no child of this layout. */ indexOf : function(child) { return this.__forward("indexOf", child); }, /** * Add a child at the specified index * * This method works on the widget's children list. Some layout managers * (e.g. {@link qx.ui.layout.HBox}) use the children order as additional * layout information. Other layout manager (e.g. {@link qx.ui.layout.Grid}) * ignore the children order for the layout process. * * @param child {LayoutItem} item to add * @param index {Integer} Index, at which the item will be inserted * @param options {Map?null} Optional layout data for item. */ addAt : function(child, index, options) { this.__forward("addAt", child, index, options); }, /** * Add an item before another already inserted item * * This method works on the widget's children list. Some layout managers * (e.g. {@link qx.ui.layout.HBox}) use the children order as additional * layout information. Other layout manager (e.g. {@link qx.ui.layout.Grid}) * ignore the children order for the layout process. * * @param child {LayoutItem} item to add * @param before {LayoutItem} item before the new item will be inserted. * @param options {Map?null} Optional layout data for item. */ addBefore : function(child, before, options) { this.__forward("addBefore", child, before, options); }, /** * Add an item after another already inserted item * * This method works on the widget's children list. Some layout managers * (e.g. {@link qx.ui.layout.HBox}) use the children order as additional * layout information. Other layout manager (e.g. {@link qx.ui.layout.Grid}) * ignore the children order for the layout process. * * @param child {LayoutItem} item to add * @param after {LayoutItem} item, after which the new item will be inserted * @param options {Map?null} Optional layout data for item. */ addAfter : function(child, after, options) { this.__forward("addAfter", child, after, options); }, /** * Remove the item at the specified index. * * This method works on the widget's children list. Some layout managers * (e.g. {@link qx.ui.layout.HBox}) use the children order as additional * layout information. Other layout manager (e.g. {@link qx.ui.layout.Grid}) * ignore the children order for the layout process. * * @param index {Integer} Index of the item to remove. * @return {qx.ui.core.LayoutItem} The removed item */ removeAt : function(index) { return this.__forward("removeAt", index); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) ************************************************************************ */ /** * Generic selection manager to bring rich desktop like selection behavior * to widgets and low-level interactive controls. * * The selection handling supports both Shift and Ctrl/Meta modifies like * known from native applications. */ qx.Class.define("qx.ui.core.selection.Abstract", { type : "abstract", extend : qx.core.Object, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ construct : function() { this.base(arguments); // {Map} Internal selection storage this.__selection = {}; }, /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fires after the selection was modified. Contains the selection under the data property. */ "changeSelection" : "qx.event.type.Data" }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * Selects the selection mode to use. * * * single: One or no element is selected * * multi: Multi items could be selected. Also allows empty selections. * * additive: Easy Web-2.0 selection mode. Allows multiple selections without modifier keys. * * one: If possible always exactly one item is selected */ mode : { check : [ "single", "multi", "additive", "one" ], init : "single", apply : "_applyMode" }, /** * Enable drag selection (multi selection of items through * dragging the mouse in pressed states). * * Only possible for the modes <code>multi</code> and <code>additive</code> */ drag : { check : "Boolean", init : false }, /** * Enable quick selection mode, where no click is needed to change the selection. * * Only possible for the modes <code>single</code> and <code>one</code>. */ quick : { check : "Boolean", init : false } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __scrollStepX : 0, __scrollStepY : 0, __scrollTimer : null, __frameScroll : null, __lastRelX : null, __lastRelY : null, __frameLocation : null, __dragStartX : null, __dragStartY : null, __inCapture : null, __mouseX : null, __mouseY : null, __moveDirectionX : null, __moveDirectionY : null, __selectionModified : null, __selectionContext : null, __leadItem : null, __selection : null, __anchorItem : null, __mouseDownOnSelected : null, // A flag that signals an user interaction, which means the selection change // was triggered by mouse or keyboard [BUG #3344] _userInteraction : false, __oldScrollTop : null, /* --------------------------------------------------------------------------- USER APIS --------------------------------------------------------------------------- */ /** * Returns the selection context. One of <code>click</code>, * <code>quick</code>, <code>drag</code> or <code>key</code> or * <code>null</code>. * * @return {String} One of <code>click</code>, <code>quick</code>, * <code>drag</code> or <code>key</code> or <code>null</code> */ getSelectionContext : function() { return this.__selectionContext; }, /** * Selects all items of the managed object. * * @return {void} */ selectAll : function() { var mode = this.getMode(); if (mode == "single" || mode == "one") { throw new Error("Can not select all items in selection mode: " + mode); } this._selectAllItems(); this._fireChange(); }, /** * Selects the given item. Replaces current selection * completely with the new item. * * Use {@link #addItem} instead if you want to add new * items to an existing selection. * * @param item {Object} Any valid item * @return {void} */ selectItem : function(item) { this._setSelectedItem(item); var mode = this.getMode(); if (mode !== "single" && mode !== "one") { this._setLeadItem(item); this._setAnchorItem(item); } this._scrollItemIntoView(item); this._fireChange(); }, /** * Adds the given item to the existing selection. * * Use {@link #selectItem} instead if you want to replace * the current selection. * * @param item {Object} Any valid item * @return {void} */ addItem : function(item) { var mode = this.getMode(); if (mode === "single" || mode === "one") { this._setSelectedItem(item); } else { if (this._getAnchorItem() == null) { this._setAnchorItem(item); } this._setLeadItem(item); this._addToSelection(item); } this._scrollItemIntoView(item); this._fireChange(); }, /** * Removes the given item from the selection. * * Use {@link #clearSelection} when you want to clear * the whole selection at once. * * @param item {Object} Any valid item * @return {void} */ removeItem : function(item) { this._removeFromSelection(item); if (this.getMode() === "one" && this.isSelectionEmpty()) { var selected = this._applyDefaultSelection(); // Do not fire any event in this case. if (selected == item) { return; } } if (this.getLeadItem() == item) { this._setLeadItem(null); } if (this._getAnchorItem() == item) { this._setAnchorItem(null); } this._fireChange(); }, /** * Selects an item range between two given items. * * @param begin {Object} Item to start with * @param end {Object} Item to end at * @return {void} */ selectItemRange : function(begin, end) { var mode = this.getMode(); if (mode == "single" || mode == "one") { throw new Error("Can not select multiple items in selection mode: " + mode); } this._selectItemRange(begin, end); this._setAnchorItem(begin); this._setLeadItem(end); this._scrollItemIntoView(end); this._fireChange(); }, /** * Clears the whole selection at once. Also * resets the lead and anchor items and their * styles. * * @return {void} */ clearSelection : function() { if (this.getMode() == "one") { var selected = this._applyDefaultSelection(true); if (selected != null) { return; } } this._clearSelection(); this._setLeadItem(null); this._setAnchorItem(null); this._fireChange(); }, /** * Replaces current selection with given array of items. * * Please note that in single selection scenarios it is more * efficient to directly use {@link #selectItem}. * * @param items {Array} Items to select */ replaceSelection : function(items) { var mode = this.getMode(); if (mode == "one" || mode === "single") { if (items.length > 1) { throw new Error("Could not select more than one items in mode: " + mode + "!"); } if (items.length == 1) { this.selectItem(items[0]); } else { this.clearSelection(); } return; } else { this._replaceMultiSelection(items); } }, /** * Get the selected item. This method does only work in <code>single</code> * selection mode. * * @return {Object} The selected item. */ getSelectedItem : function() { var mode = this.getMode(); if (mode === "single" || mode === "one") { var result = this._getSelectedItem(); return result != undefined ? result : null; } throw new Error("The method getSelectedItem() is only supported in 'single' and 'one' selection mode!"); }, /** * Returns an array of currently selected items. * * Note: The result is only a set of selected items, so the order can * differ from the sequence in which the items were added. * * @return {Object[]} List of items. */ getSelection : function() { return qx.lang.Object.getValues(this.__selection); }, /** * Returns the selection sorted by the index in the * container of the selection (the assigned widget) * * @return {Object[]} Sorted list of items */ getSortedSelection : function() { var children = this.getSelectables(); var sel = qx.lang.Object.getValues(this.__selection); sel.sort(function(a, b) { return children.indexOf(a) - children.indexOf(b); }); return sel; }, /** * Detects whether the given item is currently selected. * * @param item {var} Any valid selectable item * @return {Boolean} Whether the item is selected */ isItemSelected : function(item) { var hash = this._selectableToHashCode(item); return this.__selection[hash] !== undefined; }, /** * Whether the selection is empty * * @return {Boolean} Whether the selection is empty */ isSelectionEmpty : function() { return qx.lang.Object.isEmpty(this.__selection); }, /** * Invert the selection. Select the non selected and deselect the selected. */ invertSelection: function() { var mode = this.getMode(); if (mode === "single" || mode === "one") { throw new Error("The method invertSelection() is only supported in 'multi' and 'additive' selection mode!"); } var selectables = this.getSelectables(); for (var i = 0; i < selectables.length; i++) { this._toggleInSelection(selectables[i]); } this._fireChange(); }, /* --------------------------------------------------------------------------- LEAD/ANCHOR SUPPORT --------------------------------------------------------------------------- */ /** * Sets the lead item. Generally the item which was last modified * by the user (clicked on etc.) * * @param value {Object} Any valid item or <code>null</code> * @return {void} */ _setLeadItem : function(value) { var old = this.__leadItem; if (old !== null) { this._styleSelectable(old, "lead", false); } if (value !== null) { this._styleSelectable(value, "lead", true); } this.__leadItem = value; }, /** * Returns the current lead item. Generally the item which was last modified * by the user (clicked on etc.) * * @return {Object} The lead item or <code>null</code> */ getLeadItem : function() { return this.__leadItem !== null ? this.__leadItem : null; }, /** * Sets the anchor item. This is the item which is the starting * point for all range selections. Normally this is the item which was * clicked on the last time without any modifier keys pressed. * * @param value {Object} Any valid item or <code>null</code> * @return {void} */ _setAnchorItem : function(value) { var old = this.__anchorItem; if (old != null) { this._styleSelectable(old, "anchor", false); } if (value != null) { this._styleSelectable(value, "anchor", true); } this.__anchorItem = value; }, /** * Returns the current anchor item. This is the item which is the starting * point for all range selections. Normally this is the item which was * clicked on the last time without any modifier keys pressed. * * @return {Object} The anchor item or <code>null</code> */ _getAnchorItem : function() { return this.__anchorItem !== null ? this.__anchorItem : null; }, /* --------------------------------------------------------------------------- BASIC SUPPORT --------------------------------------------------------------------------- */ /** * Whether the given item is selectable. * * @param item {var} Any item * @return {Boolean} <code>true</code> when the item is selectable */ _isSelectable : function(item) { throw new Error("Abstract method call: _isSelectable()"); }, /** * Finds the selectable instance from a mouse event * * @param event {qx.event.type.Mouse} The mouse event * @return {Object|null} The resulting selectable */ _getSelectableFromMouseEvent : function(event) { var target = event.getTarget(); // check for target (may be null when leaving the viewport) [BUG #4378] if (target && this._isSelectable(target)) { return target; } return null; }, /** * Returns an unique hashcode for the given item. * * @param item {var} Any item * @return {String} A valid hashcode */ _selectableToHashCode : function(item) { throw new Error("Abstract method call: _selectableToHashCode()"); }, /** * Updates the style (appearance) of the given item. * * @param item {var} Item to modify * @param type {String} Any of <code>selected</code>, <code>anchor</code> or <code>lead</code> * @param enabled {Boolean} Whether the given style should be added or removed. * @return {void} */ _styleSelectable : function(item, type, enabled) { throw new Error("Abstract method call: _styleSelectable()"); }, /** * Enables capturing of the container. * * @return {void} */ _capture : function() { throw new Error("Abstract method call: _capture()"); }, /** * Releases capturing of the container * * @return {void} */ _releaseCapture : function() { throw new Error("Abstract method call: _releaseCapture()"); }, /* --------------------------------------------------------------------------- DIMENSION AND LOCATION --------------------------------------------------------------------------- */ /** * Returns the location of the container * * @return {Map} Map with the keys <code>top</code>, <code>right</code>, * <code>bottom</code> and <code>left</code>. */ _getLocation : function() { throw new Error("Abstract method call: _getLocation()"); }, /** * Returns the dimension of the container (available scrolling space). * * @return {Map} Map with the keys <code>width</code> and <code>height</code>. */ _getDimension : function() { throw new Error("Abstract method call: _getDimension()"); }, /** * Returns the relative (to the container) horizontal location of the given item. * * @param item {var} Any item * @return {Map} A map with the keys <code>left</code> and <code>right</code>. */ _getSelectableLocationX : function(item) { throw new Error("Abstract method call: _getSelectableLocationX()"); }, /** * Returns the relative (to the container) horizontal location of the given item. * * @param item {var} Any item * @return {Map} A map with the keys <code>top</code> and <code>bottom</code>. */ _getSelectableLocationY : function(item) { throw new Error("Abstract method call: _getSelectableLocationY()"); }, /* --------------------------------------------------------------------------- SCROLL SUPPORT --------------------------------------------------------------------------- */ /** * Returns the scroll position of the container. * * @return {Map} Map with the keys <code>left</code> and <code>top</code>. */ _getScroll : function() { throw new Error("Abstract method call: _getScroll()"); }, /** * Scrolls by the given offset * * @param xoff {Integer} Horizontal offset to scroll by * @param yoff {Integer} Vertical offset to scroll by * @return {void} */ _scrollBy : function(xoff, yoff) { throw new Error("Abstract method call: _scrollBy()"); }, /** * Scrolls the given item into the view (make it visible) * * @param item {var} Any item * @return {void} */ _scrollItemIntoView : function(item) { throw new Error("Abstract method call: _scrollItemIntoView()"); }, /* --------------------------------------------------------------------------- QUERY SUPPORT --------------------------------------------------------------------------- */ /** * Returns all selectable items of the container. * * @param all {boolean} true for all selectables, false for the * selectables the user can interactively select * @return {Array} A list of items */ getSelectables : function(all) { throw new Error("Abstract method call: getSelectables()"); }, /** * Returns all selectable items between the two given items. * * The items could be given in any order. * * @param item1 {var} First item * @param item2 {var} Second item * @return {Array} List of items */ _getSelectableRange : function(item1, item2) { throw new Error("Abstract method call: _getSelectableRange()"); }, /** * Returns the first selectable item. * * @return {var} The first selectable item */ _getFirstSelectable : function() { throw new Error("Abstract method call: _getFirstSelectable()"); }, /** * Returns the last selectable item. * * @return {var} The last selectable item */ _getLastSelectable : function() { throw new Error("Abstract method call: _getLastSelectable()"); }, /** * Returns a selectable item which is related to the given * <code>item</code> through the value of <code>relation</code>. * * @param item {var} Any item * @param relation {String} A valid relation: <code>above</code>, * <code>right</code>, <code>under</code> or <code>left</code> * @return {var} The related item */ _getRelatedSelectable : function(item, relation) { throw new Error("Abstract method call: _getRelatedSelectable()"); }, /** * Returns the item which should be selected on pageUp/pageDown. * * May also scroll to the needed position. * * @param lead {var} The current lead item * @param up {Boolean?false} Which page key was pressed: * <code>up</code> or <code>down</code>. * @return {void} */ _getPage : function(lead, up) { throw new Error("Abstract method call: _getPage()"); }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyMode : function(value, old) { this._setLeadItem(null); this._setAnchorItem(null); this._clearSelection(); // Mode "one" requires one selected item if (value === "one") { this._applyDefaultSelection(true); } this._fireChange(); }, /* --------------------------------------------------------------------------- MOUSE SUPPORT --------------------------------------------------------------------------- */ /** * This method should be connected to the <code>mouseover</code> event * of the managed object. * * @param event {qx.event.type.Mouse} A valid mouse event * @return {void} */ handleMouseOver : function(event) { // All browsers (except Opera) fire a native "mouseover" event when a scroll appears // by keyboard interaction. We have to ignore the event to avoid a selection for // "mouseover" (quick selection). For more details see [BUG #4225] if(this.__oldScrollTop != null && this.__oldScrollTop != this._getScroll().top) { this.__oldScrollTop = null; return; } // this is a method invoked by an user interaction, so be careful to // set / clear the mark this._userInteraction [BUG #3344] this._userInteraction = true; if (!this.getQuick()) { this._userInteraction = false; return; } var mode = this.getMode(); if (mode !== "one" && mode !== "single") { this._userInteraction = false; return; } var item = this._getSelectableFromMouseEvent(event); if (item === null) { this._userInteraction = false; return; } this._setSelectedItem(item); // Be sure that item is in view // This does not feel good when mouseover is used // this._scrollItemIntoView(item); // Fire change event as needed this._fireChange("quick"); this._userInteraction = false; }, /** * This method should be connected to the <code>mousedown</code> event * of the managed object. * * @param event {qx.event.type.Mouse} A valid mouse event * @return {void} */ handleMouseDown : function(event) { // this is a method invoked by an user interaction, so be careful to // set / clear the mark this._userInteraction [BUG #3344] this._userInteraction = true; var item = this._getSelectableFromMouseEvent(event); if (item === null) { this._userInteraction = false; return; } // Read in keyboard modifiers var isCtrlPressed = event.isCtrlPressed() || (qx.core.Environment.get("os.name") == "osx" && event.isMetaPressed()); var isShiftPressed = event.isShiftPressed(); // Clicking on selected items deselect on mouseup, not on mousedown if (this.isItemSelected(item) && !isShiftPressed && !isCtrlPressed && !this.getDrag()) { this.__mouseDownOnSelected = item; this._userInteraction = false; return; } else { this.__mouseDownOnSelected = null; } // Be sure that item is in view this._scrollItemIntoView(item); // Action depends on selected mode switch(this.getMode()) { case "single": case "one": this._setSelectedItem(item); break; case "additive": this._setLeadItem(item); this._setAnchorItem(item); this._toggleInSelection(item); break; case "multi": // Update lead item this._setLeadItem(item); // Create/Update range selection if (isShiftPressed) { var anchor = this._getAnchorItem(); if (anchor === null) { anchor = this._getFirstSelectable(); this._setAnchorItem(anchor); } this._selectItemRange(anchor, item, isCtrlPressed); } // Toggle in selection else if (isCtrlPressed) { this._setAnchorItem(item); this._toggleInSelection(item); } // Replace current selection else { this._setAnchorItem(item); this._setSelectedItem(item); } break; } // Drag selection var mode = this.getMode(); if ( this.getDrag() && mode !== "single" && mode !== "one" && !isShiftPressed && !isCtrlPressed ) { // Cache location/scroll data this.__frameLocation = this._getLocation(); this.__frameScroll = this._getScroll(); // Store position at start this.__dragStartX = event.getDocumentLeft() + this.__frameScroll.left; this.__dragStartY = event.getDocumentTop() + this.__frameScroll.top; // Switch to capture mode this.__inCapture = true; this._capture(); } // Fire change event as needed this._fireChange("click"); this._userInteraction = false; }, /** * This method should be connected to the <code>mouseup</code> event * of the managed object. * * @param event {qx.event.type.Mouse} A valid mouse event * @return {void} */ handleMouseUp : function(event) { // this is a method invoked by an user interaction, so be careful to // set / clear the mark this._userInteraction [BUG #3344] this._userInteraction = true; // Read in keyboard modifiers var isCtrlPressed = event.isCtrlPressed() || (qx.core.Environment.get("os.name") == "osx" && event.isMetaPressed()); var isShiftPressed = event.isShiftPressed(); if (!isCtrlPressed && !isShiftPressed && this.__mouseDownOnSelected != null) { var item = this._getSelectableFromMouseEvent(event); if (item === null || !this.isItemSelected(item)) { this._userInteraction = false; return; } var mode = this.getMode(); if (mode === "additive") { // Remove item from selection this._removeFromSelection(item); } else { // Replace selection this._setSelectedItem(item); if (this.getMode() === "multi") { this._setLeadItem(item); this._setAnchorItem(item); } } this._userInteraction = false; } // Cleanup operation this._cleanup(); }, /** * This method should be connected to the <code>losecapture</code> event * of the managed object. * * @param event {qx.event.type.Mouse} A valid mouse event * @return {void} */ handleLoseCapture : function(event) { this._cleanup(); }, /** * This method should be connected to the <code>mousemove</code> event * of the managed object. * * @param event {qx.event.type.Mouse} A valid mouse event * @return {void} */ handleMouseMove : function(event) { // Only relevant when capturing is enabled if (!this.__inCapture) { return; } // Update mouse position cache this.__mouseX = event.getDocumentLeft(); this.__mouseY = event.getDocumentTop(); // this is a method invoked by an user interaction, so be careful to // set / clear the mark this._userInteraction [BUG #3344] this._userInteraction = true; // Detect move directions var dragX = this.__mouseX + this.__frameScroll.left; if (dragX > this.__dragStartX) { this.__moveDirectionX = 1; } else if (dragX < this.__dragStartX) { this.__moveDirectionX = -1; } else { this.__moveDirectionX = 0; } var dragY = this.__mouseY + this.__frameScroll.top; if (dragY > this.__dragStartY) { this.__moveDirectionY = 1; } else if (dragY < this.__dragStartY) { this.__moveDirectionY = -1; } else { this.__moveDirectionY = 0; } // Update scroll steps var location = this.__frameLocation; if (this.__mouseX < location.left) { this.__scrollStepX = this.__mouseX - location.left; } else if (this.__mouseX > location.right) { this.__scrollStepX = this.__mouseX - location.right; } else { this.__scrollStepX = 0; } if (this.__mouseY < location.top) { this.__scrollStepY = this.__mouseY - location.top; } else if (this.__mouseY > location.bottom) { this.__scrollStepY = this.__mouseY - location.bottom; } else { this.__scrollStepY = 0; } // Dynamically create required timer instance if (!this.__scrollTimer) { this.__scrollTimer = new qx.event.Timer(100); this.__scrollTimer.addListener("interval", this._onInterval, this); } // Start interval this.__scrollTimer.start(); // Auto select based on new cursor position this._autoSelect(); event.stopPropagation(); this._userInteraction = false; }, /** * This method should be connected to the <code>addItem</code> event * of the managed object. * * @param e {qx.event.type.Data} The event object * @return {void} */ handleAddItem : function(e) { var item = e.getData(); if (this.getMode() === "one" && this.isSelectionEmpty()) { this.addItem(item); } }, /** * This method should be connected to the <code>removeItem</code> event * of the managed object. * * @param e {qx.event.type.Data} The event object * @return {void} */ handleRemoveItem : function(e) { this.removeItem(e.getData()); }, /* --------------------------------------------------------------------------- MOUSE SUPPORT INTERNALS --------------------------------------------------------------------------- */ /** * Stops all timers, release capture etc. to cleanup drag selection */ _cleanup : function() { if (!this.getDrag() && this.__inCapture) { return; } // Fire change event if needed if (this.__selectionModified) { this._fireChange("click"); } // Remove flags delete this.__inCapture; delete this.__lastRelX; delete this.__lastRelY; // Stop capturing this._releaseCapture(); // Stop timer if (this.__scrollTimer) { this.__scrollTimer.stop(); } }, /** * Event listener for timer used by drag selection * * @param e {qx.event.type.Event} Timer event */ _onInterval : function(e) { // Scroll by defined block size this._scrollBy(this.__scrollStepX, this.__scrollStepY); // TODO: Optimization: Detect real scroll changes first? // Update scroll cache this.__frameScroll = this._getScroll(); // Auto select based on new scroll position and cursor this._autoSelect(); }, /** * Automatically selects items based on the mouse movement during a drag selection */ _autoSelect : function() { var inner = this._getDimension(); // Get current relative Y position and compare it with previous one var relX = Math.max(0, Math.min(this.__mouseX - this.__frameLocation.left, inner.width)) + this.__frameScroll.left; var relY = Math.max(0, Math.min(this.__mouseY - this.__frameLocation.top, inner.height)) + this.__frameScroll.top; // Compare old and new relative coordinates (for performance reasons) if (this.__lastRelX === relX && this.__lastRelY === relY) { return; } this.__lastRelX = relX; this.__lastRelY = relY; // Cache anchor var anchor = this._getAnchorItem(); var lead = anchor; // Process X-coordinate var moveX = this.__moveDirectionX; var nextX, locationX; while (moveX !== 0) { // Find next item to process depending on current scroll direction nextX = moveX > 0 ? this._getRelatedSelectable(lead, "right") : this._getRelatedSelectable(lead, "left"); // May be null (e.g. first/last item) if (nextX !== null) { locationX = this._getSelectableLocationX(nextX); // Continue when the item is in the visible area if ( (moveX > 0 && locationX.left <= relX) || (moveX < 0 && locationX.right >= relX) ) { lead = nextX; continue; } } // Otherwise break break; } // Process Y-coordinate var moveY = this.__moveDirectionY; var nextY, locationY; while (moveY !== 0) { // Find next item to process depending on current scroll direction nextY = moveY > 0 ? this._getRelatedSelectable(lead, "under") : this._getRelatedSelectable(lead, "above"); // May be null (e.g. first/last item) if (nextY !== null) { locationY = this._getSelectableLocationY(nextY); // Continue when the item is in the visible area if ( (moveY > 0 && locationY.top <= relY) || (moveY < 0 && locationY.bottom >= relY) ) { lead = nextY; continue; } } // Otherwise break break; } // Differenciate between the two supported modes var mode = this.getMode(); if (mode === "multi") { // Replace current selection with new range this._selectItemRange(anchor, lead); } else if (mode === "additive") { // Behavior depends on the fact whether the // anchor item is selected or not if (this.isItemSelected(anchor)) { this._selectItemRange(anchor, lead, true); } else { this._deselectItemRange(anchor, lead); } // Improve performance. This mode does not rely // on full ranges as it always extend the old // selection/deselection. this._setAnchorItem(lead); } // Fire change event as needed this._fireChange("drag"); }, /* --------------------------------------------------------------------------- KEYBOARD SUPPORT --------------------------------------------------------------------------- */ /** * {Map} All supported navigation keys * * @lint ignoreReferenceField(__navigationKeys) */ __navigationKeys : { Home : 1, Down : 1 , Right : 1, PageDown : 1, End : 1, Up : 1, Left : 1, PageUp : 1 }, /** * This method should be connected to the <code>keypress</code> event * of the managed object. * * @param event {qx.event.type.KeySequence} A valid key sequence event * @return {void} */ handleKeyPress : function(event) { // this is a method invoked by an user interaction, so be careful to // set / clear the mark this._userInteraction [BUG #3344] this._userInteraction = true; var current, next; var key = event.getKeyIdentifier(); var mode = this.getMode(); // Support both control keys on Mac var isCtrlPressed = event.isCtrlPressed() || (qx.core.Environment.get("os.name") == "osx" && event.isMetaPressed()); var isShiftPressed = event.isShiftPressed(); var consumed = false; if (key === "A" && isCtrlPressed) { if (mode !== "single" && mode !== "one") { this._selectAllItems(); consumed = true; } } else if (key === "Escape") { if (mode !== "single" && mode !== "one") { this._clearSelection(); consumed = true; } } else if (key === "Space") { var lead = this.getLeadItem(); if (lead != null && !isShiftPressed) { if (isCtrlPressed || mode === "additive") { this._toggleInSelection(lead); } else { this._setSelectedItem(lead); } consumed = true; } } else if (this.__navigationKeys[key]) { consumed = true; if (mode === "single" || mode == "one") { current = this._getSelectedItem(); } else { current = this.getLeadItem(); } if (current !== null) { switch(key) { case "Home": next = this._getFirstSelectable(); break; case "End": next = this._getLastSelectable(); break; case "Up": next = this._getRelatedSelectable(current, "above"); break; case "Down": next = this._getRelatedSelectable(current, "under"); break; case "Left": next = this._getRelatedSelectable(current, "left"); break; case "Right": next = this._getRelatedSelectable(current, "right"); break; case "PageUp": next = this._getPage(current, true); break; case "PageDown": next = this._getPage(current, false); break; } } else { switch(key) { case "Home": case "Down": case "Right": case "PageDown": next = this._getFirstSelectable(); break; case "End": case "Up": case "Left": case "PageUp": next = this._getLastSelectable(); break; } } // Process result if (next !== null) { switch(mode) { case "single": case "one": this._setSelectedItem(next); break; case "additive": this._setLeadItem(next); break; case "multi": if (isShiftPressed) { var anchor = this._getAnchorItem(); if (anchor === null) { this._setAnchorItem(anchor = this._getFirstSelectable()); } this._setLeadItem(next); this._selectItemRange(anchor, next, isCtrlPressed); } else { this._setAnchorItem(next); this._setLeadItem(next); if (!isCtrlPressed) { this._setSelectedItem(next); } } break; } this.__oldScrollTop = this._getScroll().top; this._scrollItemIntoView(next); } } if (consumed) { // Stop processed events event.stop(); // Fire change event as needed this._fireChange("key"); } this._userInteraction = false; }, /* --------------------------------------------------------------------------- SUPPORT FOR ITEM RANGES --------------------------------------------------------------------------- */ /** * Adds all items to the selection */ _selectAllItems : function() { var range = this.getSelectables(); for (var i=0, l=range.length; i<l; i++) { this._addToSelection(range[i]); } }, /** * Clears current selection */ _clearSelection : function() { var selection = this.__selection; for (var hash in selection) { this._removeFromSelection(selection[hash]); } this.__selection = {}; }, /** * Select a range from <code>item1</code> to <code>item2</code>. * * @param item1 {Object} Start with this item * @param item2 {Object} End with this item * @param extend {Boolean?false} Whether the current * selection should be replaced or extended. */ _selectItemRange : function(item1, item2, extend) { var range = this._getSelectableRange(item1, item2); // Remove items which are not in the detected range if (!extend) { var selected = this.__selection; var mapped = this.__rangeToMap(range); for (var hash in selected) { if (!mapped[hash]) { this._removeFromSelection(selected[hash]); } } } // Add new items to the selection for (var i=0, l=range.length; i<l; i++) { this._addToSelection(range[i]); } }, /** * Deselect all items between <code>item1</code> and <code>item2</code>. * * @param item1 {Object} Start with this item * @param item2 {Object} End with this item */ _deselectItemRange : function(item1, item2) { var range = this._getSelectableRange(item1, item2); for (var i=0, l=range.length; i<l; i++) { this._removeFromSelection(range[i]); } }, /** * Internal method to convert a range to a map of hash * codes for faster lookup during selection compare routines. * * @param range {Array} List of selectable items */ __rangeToMap : function(range) { var mapped = {}; var item; for (var i=0, l=range.length; i<l; i++) { item = range[i]; mapped[this._selectableToHashCode(item)] = item; } return mapped; }, /* --------------------------------------------------------------------------- SINGLE ITEM QUERY AND MODIFICATION --------------------------------------------------------------------------- */ /** * Returns the first selected item. Only makes sense * when using manager in single selection mode. * * @return {var} The selected item (or <code>null</code>) */ _getSelectedItem : function() { for (var hash in this.__selection) { return this.__selection[hash]; } return null; }, /** * Replace current selection with given item. * * @param item {var} Any valid selectable item * @return {void} */ _setSelectedItem : function(item) { if (this._isSelectable(item)) { // If already selected try to find out if this is the only item var current = this.__selection; var hash = this._selectableToHashCode(item); if (!current[hash] || qx.lang.Object.hasMinLength(current, 2)) { this._clearSelection(); this._addToSelection(item); } } }, /* --------------------------------------------------------------------------- MODIFY ITEM SELECTION --------------------------------------------------------------------------- */ /** * Adds an item to the current selection. * * @param item {Object} Any item */ _addToSelection : function(item) { var hash = this._selectableToHashCode(item); if (this.__selection[hash] == null && this._isSelectable(item)) { this.__selection[hash] = item; this._styleSelectable(item, "selected", true); this.__selectionModified = true; } }, /** * Toggles the item e.g. remove it when already selected * or select it when currently not. * * @param item {Object} Any item */ _toggleInSelection : function(item) { var hash = this._selectableToHashCode(item); if (this.__selection[hash] == null) { this.__selection[hash] = item; this._styleSelectable(item, "selected", true); } else { delete this.__selection[hash]; this._styleSelectable(item, "selected", false); } this.__selectionModified = true; }, /** * Removes the given item from the current selection. * * @param item {Object} Any item */ _removeFromSelection : function(item) { var hash = this._selectableToHashCode(item); if (this.__selection[hash] != null) { delete this.__selection[hash]; this._styleSelectable(item, "selected", false); this.__selectionModified = true; } }, /** * Replaces current selection with items from given array. * * @param items {Array} List of items to select */ _replaceMultiSelection : function(items) { var modified = false; // Build map from hash codes and filter non-selectables var selectable, hash; var incoming = {}; for (var i=0, l=items.length; i<l; i++) { selectable = items[i]; if (this._isSelectable(selectable)) { hash = this._selectableToHashCode(selectable); incoming[hash] = selectable; } } // Remember last var first = items[0]; var last = selectable; // Clear old entries from map var current = this.__selection; for (var hash in current) { if (incoming[hash]) { // Reduce map to make next loop faster delete incoming[hash]; } else { // update internal map selectable = current[hash]; delete current[hash]; // apply styling this._styleSelectable(selectable, "selected", false); // remember that the selection has been modified modified = true; } } // Add remaining selectables to selection for (var hash in incoming) { // update internal map selectable = current[hash] = incoming[hash]; // apply styling this._styleSelectable(selectable, "selected", true); // remember that the selection has been modified modified = true; } // Do not do anything if selection is equal to previous one if (!modified) { return false; } // Scroll last incoming item into view this._scrollItemIntoView(last); // Reset anchor and lead item this._setLeadItem(first); this._setAnchorItem(first); // Finally fire change event this.__selectionModified = true; this._fireChange(); }, /** * Fires the selection change event if the selection has * been modified. * * @param context {String} One of <code>click</code>, <code>quick</code>, * <code>drag</code> or <code>key</code> or <code>null</code> */ _fireChange : function(context) { if (this.__selectionModified) { // Store context this.__selectionContext = context || null; // Fire data event which contains the current selection this.fireDataEvent("changeSelection", this.getSelection()); delete this.__selectionModified; } }, /** * Applies the default selection. The default item is the first item. * * @param force {Boolean} Whether the default selection sould forced. * * @return {var} The selected item. */ _applyDefaultSelection : function(force) { if (force === true || this.getMode() === "one" && this.isSelectionEmpty()) { var first = this._getFirstSelectable(); if (first != null) { this.selectItem(first); } return first; } return null; } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this._disposeObjects("__scrollTimer"); this.__selection = this.__mouseDownOnSelected = this.__anchorItem = null; this.__leadItem = null; } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) ************************************************************************ */ /** * A selection manager, which handles the selection in widgets. */ qx.Class.define("qx.ui.core.selection.Widget", { extend : qx.ui.core.selection.Abstract, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param widget {qx.ui.core.Widget} The widget to connect to */ construct : function(widget) { this.base(arguments); this.__widget = widget; }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __widget : null, /* --------------------------------------------------------------------------- BASIC SUPPORT --------------------------------------------------------------------------- */ // overridden _isSelectable : function(item) { return this._isItemSelectable(item) && item.getLayoutParent() === this.__widget; }, // overridden _selectableToHashCode : function(item) { return item.$$hash; }, // overridden _styleSelectable : function(item, type, enabled) { enabled ? item.addState(type) : item.removeState(type); }, // overridden _capture : function() { this.__widget.capture(); }, // overridden _releaseCapture : function() { this.__widget.releaseCapture(); }, /** * Helper to return the selectability of the item concerning the * user interaaction. * * @param item {qx.ui.core.Widget} The item to check. * @return {Boolean} true, if the item is selectable. */ _isItemSelectable : function(item) { if (this._userInteraction) { return item.isVisible() && item.isEnabled(); } else { return item.isVisible(); } }, /** * Returns the connected widget. * @return {qx.ui.core.Widget} The widget */ _getWidget : function() { return this.__widget; }, /* --------------------------------------------------------------------------- DIMENSION AND LOCATION --------------------------------------------------------------------------- */ // overridden _getLocation : function() { var elem = this.__widget.getContentElement().getDomElement(); return elem ? qx.bom.element.Location.get(elem) : null; }, // overridden _getDimension : function() { return this.__widget.getInnerSize(); }, // overridden _getSelectableLocationX : function(item) { var computed = item.getBounds(); if (computed) { return { left : computed.left, right : computed.left + computed.width }; } }, // overridden _getSelectableLocationY : function(item) { var computed = item.getBounds(); if (computed) { return { top : computed.top, bottom : computed.top + computed.height }; } }, /* --------------------------------------------------------------------------- SCROLL SUPPORT --------------------------------------------------------------------------- */ // overridden _getScroll : function() { return { left : 0, top : 0 }; }, // overridden _scrollBy : function(xoff, yoff) { // empty implementation }, // overridden _scrollItemIntoView : function(item) { this.__widget.scrollChildIntoView(item); }, /* --------------------------------------------------------------------------- QUERY SUPPORT --------------------------------------------------------------------------- */ // overridden getSelectables : function(all) { // if only the user selectables should be returned var oldUserInteraction = false; if (!all) { oldUserInteraction = this._userInteraction; this._userInteraction = true; } var children = this.__widget.getChildren(); var result = []; var child; for (var i=0, l=children.length; i<l; i++) { child = children[i]; if (this._isItemSelectable(child)) { result.push(child); } } // reset to the former user interaction state this._userInteraction = oldUserInteraction; return result; }, // overridden _getSelectableRange : function(item1, item2) { // Fast path for identical items if (item1 === item2) { return [item1]; } // Iterate over children and collect all items // between the given two (including them) var children = this.__widget.getChildren(); var result = []; var active = false; var child; for (var i=0, l=children.length; i<l; i++) { child = children[i]; if (child === item1 || child === item2) { if (active) { result.push(child); break; } else { active = true; } } if (active && this._isItemSelectable(child)) { result.push(child); } } return result; }, // overridden _getFirstSelectable : function() { var children = this.__widget.getChildren(); for (var i=0, l=children.length; i<l; i++) { if (this._isItemSelectable(children[i])) { return children[i]; } } return null; }, // overridden _getLastSelectable : function() { var children = this.__widget.getChildren(); for (var i=children.length-1; i>0; i--) { if (this._isItemSelectable(children[i])) { return children[i]; } } return null; }, // overridden _getRelatedSelectable : function(item, relation) { var vertical = this.__widget.getOrientation() === "vertical"; var children = this.__widget.getChildren(); var index = children.indexOf(item); var sibling; if ((vertical && relation === "above") || (!vertical && relation === "left")) { for (var i=index-1; i>=0; i--) { sibling = children[i]; if (this._isItemSelectable(sibling)) { return sibling; } } } else if ((vertical && relation === "under") || (!vertical && relation === "right")) { for (var i=index+1; i<children.length; i++) { sibling = children[i]; if (this._isItemSelectable(sibling)) { return sibling; } } } return null; }, // overridden _getPage : function(lead, up) { if (up) { return this._getFirstSelectable(); } else { return this._getLastSelectable(); } } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this.__widget = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) ************************************************************************ */ /** * A selection manager, which handles the selection in widgets extending * {@link qx.ui.core.scroll.AbstractScrollArea}. */ qx.Class.define("qx.ui.core.selection.ScrollArea", { extend : qx.ui.core.selection.Widget, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /* --------------------------------------------------------------------------- BASIC SUPPORT --------------------------------------------------------------------------- */ // overridden _isSelectable : function(item) { return this._isItemSelectable(item) && item.getLayoutParent() === this._getWidget().getChildrenContainer(); }, /* --------------------------------------------------------------------------- DIMENSION AND LOCATION --------------------------------------------------------------------------- */ // overridden _getDimension : function() { return this._getWidget().getPaneSize(); }, /* --------------------------------------------------------------------------- SCROLL SUPPORT --------------------------------------------------------------------------- */ // overridden _getScroll : function() { var widget = this._getWidget(); return { left : widget.getScrollX(), top : widget.getScrollY() }; }, // overridden _scrollBy : function(xoff, yoff) { var widget = this._getWidget(); widget.scrollByX(xoff); widget.scrollByY(yoff); }, /* --------------------------------------------------------------------------- QUERY SUPPORT --------------------------------------------------------------------------- */ // overridden _getPage : function(lead, up) { var selectables = this.getSelectables(); var length = selectables.length; var start = selectables.indexOf(lead); // Given lead is not a selectable?!? if (start === -1) { throw new Error("Invalid lead item: " + lead); } var widget = this._getWidget(); var scrollTop = widget.getScrollY(); var innerHeight = widget.getInnerSize().height; var top, bottom, found; if (up) { var min = scrollTop; var i=start; // Loop required to scroll pages up dynamically while(1) { // Iterate through all selectables from start for (; i>=0; i--) { top = widget.getItemTop(selectables[i]); // This item is out of the visible block if (top < min) { // Use previous one found = i+1; break; } } // Nothing found. Return first item. if (found == null) { var first = this._getFirstSelectable(); return first == lead ? null : first; } // Found item, but is identical to start or even before start item // Update min positon and try on previous page if (found >= start) { // Reduce min by the distance of the lead item to the visible // bottom edge. This is needed instead of a simple subtraction // of the inner height to keep the last lead visible on page key // presses. This is the behavior of native toolkits as well. min -= innerHeight + scrollTop - widget.getItemBottom(lead); found = null; continue; } // Return selectable return selectables[found]; } } else { var max = innerHeight + scrollTop; var i=start; // Loop required to scroll pages down dynamically while(1) { // Iterate through all selectables from start for (; i<length; i++) { bottom = widget.getItemBottom(selectables[i]); // This item is out of the visible block if (bottom > max) { // Use previous one found = i-1; break; } } // Nothing found. Return last item. if (found == null) { var last = this._getLastSelectable(); return last == lead ? null : last; } // Found item, but is identical to start or even before start item // Update max position and try on next page if (found <= start) { // Extend max by the distance of the lead item to the visible // top edge. This is needed instead of a simple addition // of the inner height to keep the last lead visible on page key // presses. This is the behavior of native toolkits as well. max += widget.getItemTop(lead) - scrollTop; found = null; continue; } // Return selectable return selectables[found]; } } } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Christian Hagendorn (chris_schmidt) ************************************************************************ */ /** * This mixin links all methods to manage the multi selection from the * internal selection manager to the widget. */ qx.Mixin.define("qx.ui.core.MMultiSelectionHandling", { /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ construct : function() { // Create selection manager var clazz = this.SELECTION_MANAGER; var manager = this.__manager = new clazz(this); // Add widget event listeners this.addListener("mousedown", manager.handleMouseDown, manager); this.addListener("mouseup", manager.handleMouseUp, manager); this.addListener("mouseover", manager.handleMouseOver, manager); this.addListener("mousemove", manager.handleMouseMove, manager); this.addListener("losecapture", manager.handleLoseCapture, manager); this.addListener("keypress", manager.handleKeyPress, manager); this.addListener("addItem", manager.handleAddItem, manager); this.addListener("removeItem", manager.handleRemoveItem, manager); // Add manager listeners manager.addListener("changeSelection", this._onSelectionChange, this); }, /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fires after the selection was modified */ "changeSelection" : "qx.event.type.Data" }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * The selection mode to use. * * For further details please have a look at: * {@link qx.ui.core.selection.Abstract#mode} */ selectionMode : { check : [ "single", "multi", "additive", "one" ], init : "single", apply : "_applySelectionMode" }, /** * Enable drag selection (multi selection of items through * dragging the mouse in pressed states). * * Only possible for the selection modes <code>multi</code> and <code>additive</code> */ dragSelection : { check : "Boolean", init : false, apply : "_applyDragSelection" }, /** * Enable quick selection mode, where no click is needed to change the selection. * * Only possible for the modes <code>single</code> and <code>one</code>. */ quickSelection : { check : "Boolean", init : false, apply : "_applyQuickSelection" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** {qx.ui.core.selection.Abstract} The selection manager */ __manager : null, /* --------------------------------------------------------------------------- USER API --------------------------------------------------------------------------- */ /** * Selects all items of the managed object. */ selectAll : function() { this.__manager.selectAll(); }, /** * Detects whether the given item is currently selected. * * @param item {qx.ui.core.Widget} Any valid selectable item. * @return {Boolean} Whether the item is selected. * @throws an exception if the item is not a child element. */ isSelected : function(item) { if (!qx.ui.core.Widget.contains(this, item)) { throw new Error("Could not test if " + item + " is selected, because it is not a child element!"); } return this.__manager.isItemSelected(item); }, /** * Adds the given item to the existing selection. * * Use {@link #setSelection} instead if you want to replace * the current selection. * * @param item {qx.ui.core.Widget} Any valid item. * @throws an exception if the item is not a child element. */ addToSelection : function(item) { if (!qx.ui.core.Widget.contains(this, item)) { throw new Error("Could not add + " + item + " to selection, because it is not a child element!"); } this.__manager.addItem(item); }, /** * Removes the given item from the selection. * * Use {@link #resetSelection} when you want to clear * the whole selection at once. * * @param item {qx.ui.core.Widget} Any valid item * @throws an exception if the item is not a child element. */ removeFromSelection : function(item) { if (!qx.ui.core.Widget.contains(this, item)) { throw new Error("Could not remove " + item + " from selection, because it is not a child element!"); } this.__manager.removeItem(item); }, /** * Selects an item range between two given items. * * @param begin {qx.ui.core.Widget} Item to start with * @param end {qx.ui.core.Widget} Item to end at */ selectRange : function(begin, end) { this.__manager.selectItemRange(begin, end); }, /** * Clears the whole selection at once. Also * resets the lead and anchor items and their * styles. */ resetSelection : function() { this.__manager.clearSelection(); }, /** * Replaces current selection with the given items. * * @param items {qx.ui.core.Widget[]} Items to select. * @throws an exception if one of the items is not a child element and if * the mode is set to <code>single</code> or <code>one</code> and * the items contains more than one item. */ setSelection : function(items) { for (var i = 0; i < items.length; i++) { if (!qx.ui.core.Widget.contains(this, items[i])) { throw new Error("Could not select " + items[i] + ", because it is not a child element!"); } } if (items.length === 0) { this.resetSelection(); } else { var currentSelection = this.getSelection(); if (!qx.lang.Array.equals(currentSelection, items)) { this.__manager.replaceSelection(items); } } }, /** * Returns an array of currently selected items. * * Note: The result is only a set of selected items, so the order can * differ from the sequence in which the items were added. * * @return {qx.ui.core.Widget[]} List of items. */ getSelection : function() { return this.__manager.getSelection(); }, /** * Returns an array of currently selected items sorted * by their index in the container. * * @return {qx.ui.core.Widget[]} Sorted list of items */ getSortedSelection : function() { return this.__manager.getSortedSelection(); }, /** * Whether the selection is empty * * @return {Boolean} Whether the selection is empty */ isSelectionEmpty : function() { return this.__manager.isSelectionEmpty(); }, /** * Returns the last selection context. * * @return {String | null} One of <code>click</code>, <code>quick</code>, * <code>drag</code> or <code>key</code> or <code>null</code>. */ getSelectionContext : function() { return this.__manager.getSelectionContext(); }, /** * Returns the internal selection manager. Use this with * caution! * * @return {qx.ui.core.selection.Abstract} The selection manager */ _getManager : function() { return this.__manager; }, /** * Returns all elements which are selectable. * * @param all {boolean} true for all selectables, false for the * selectables the user can interactively select * @return {qx.ui.core.Widget[]} The contained items. */ getSelectables: function(all) { return this.__manager.getSelectables(all); }, /** * Invert the selection. Select the non selected and deselect the selected. */ invertSelection: function() { this.__manager.invertSelection(); }, /** * Returns the current lead item. Generally the item which was last modified * by the user (clicked on etc.) * * @return {qx.ui.core.Widget} The lead item or <code>null</code> */ _getLeadItem : function() { var mode = this.__manager.getMode(); if (mode === "single" || mode === "one") { return this.__manager.getSelectedItem(); } else { return this.__manager.getLeadItem(); } }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applySelectionMode : function(value, old) { this.__manager.setMode(value); }, // property apply _applyDragSelection : function(value, old) { this.__manager.setDrag(value); }, // property apply _applyQuickSelection : function(value, old) { this.__manager.setQuick(value); }, /* --------------------------------------------------------------------------- EVENT HANDLER --------------------------------------------------------------------------- */ /** * Event listener for <code>changeSelection</code> event on selection manager. * * @param e {qx.event.type.Data} Data event */ _onSelectionChange : function(e) { this.fireDataEvent("changeSelection", e.getData()); } }, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ destruct : function() { this._disposeObjects("__manager"); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Christian Hagendorn (chris_schmidt) * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Each object, which should support multiselection selection have to * implement this interface. */ qx.Interface.define("qx.ui.core.IMultiSelection", { extend: qx.ui.core.ISingleSelection, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** * Selects all items of the managed object. */ selectAll : function() { return true; }, /** * Adds the given item to the existing selection. * * @param item {qx.ui.core.Widget} Any valid item * @throws an exception if the item is not a child element. */ addToSelection : function(item) { return arguments.length == 1; }, /** * Removes the given item from the selection. * * Use {@link qx.ui.core.ISingleSelection#resetSelection} when you * want to clear the whole selection at once. * * @param item {qx.ui.core.Widget} Any valid item * @throws an exception if the item is not a child element. */ removeFromSelection : function(item) { return arguments.length == 1; } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2011 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Mixin holding the handler for the two axis mouse wheel scrolling. Please * keep in mind that the including widget has to have the scroll bars * implemented as child controls named <code>scrollbar-x</code> and * <code>scrollbar-y</code> to get the handler working. Also, you have to * attach the listener yourself. */ qx.Mixin.define("qx.ui.core.scroll.MWheelHandling", { members : { /** * Mouse wheel event handler * * @param e {qx.event.type.Mouse} Mouse event */ _onMouseWheel : function(e) { var showX = this._isChildControlVisible("scrollbar-x"); var showY = this._isChildControlVisible("scrollbar-y"); var scrollbarY = showY ? this.getChildControl("scrollbar-y", true) : null; var scrollbarX = showX ? this.getChildControl("scrollbar-x", true) : null; var deltaY = e.getWheelDelta("y"); var deltaX = e.getWheelDelta("x"); var endY = !showY; var endX = !showX; // y case if (scrollbarY) { var steps = parseInt(deltaY); if (steps !== 0) { scrollbarY.scrollBySteps(steps); } var position = scrollbarY.getPosition(); var max = scrollbarY.getMaximum(); // pass the event to the parent if the scrollbar is at an edge if (steps < 0 && position <= 0 || steps > 0 && position >= max) { endY = true; } } // x case if (scrollbarX) { var steps = parseInt(deltaX); if (steps !== 0) { scrollbarX.scrollBySteps(steps); } var position = scrollbarX.getPosition(); var max = scrollbarX.getMaximum(); // pass the event to the parent if the scrollbar is at an edge if (steps < 0 && position <= 0 || steps > 0 && position >= max) { endX = true; } } // pass the event to the parent if both scrollbars are at the end if (!endY || !endX) { // Stop bubbling and native event only if a scrollbar is visible e.stop(); } } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's left-level directory for details. Authors: * Fabian Jakobs (fjakobs) ************************************************************************ */ qx.core.Environment.add("qx.nativeScrollBars", false); /** * Include this widget if you want to create scrollbars depending on the global * "qx.nativeScrollBars" setting. */ qx.Mixin.define("qx.ui.core.scroll.MScrollBarFactory", { members : { /** * Creates a new scrollbar. This can either be a styled qooxdoo scrollbar * or a native browser scrollbar. * * @param orientation {String?"horizontal"} The initial scroll bar orientation * @return {qx.ui.core.scroll.IScrollBar} The scrollbar instance */ _createScrollBar : function(orientation) { if (qx.core.Environment.get("qx.nativeScrollBars")) { return new qx.ui.core.scroll.NativeScrollBar(orientation); } else { return new qx.ui.core.scroll.ScrollBar(orientation); } } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's left-level directory for details. Authors: * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * All widget used as scrollbars must implement this interface. */ qx.Interface.define("qx.ui.core.scroll.IScrollBar", { events : { /** Fired if the user scroll */ "scroll" : "qx.event.type.Data" }, properties : { /** * The scroll bar orientation */ orientation : {}, /** * The maximum value (difference between available size and * content size). */ maximum : {}, /** * Position of the scrollbar (which means the scroll left/top of the * attached area's pane) * * Strictly validates according to {@link #maximum}. * Does not apply any correction to the incoming value. If you depend * on this, please use {@link #scrollTo} instead. */ position : {}, /** * Factor to apply to the width/height of the knob in relation * to the dimension of the underlying area. */ knobFactor : {} }, members : { /** * Scrolls to the given position. * * This method automatically corrects the given position to respect * the {@link #maximum}. * * @param position {Integer} Scroll to this position. Must be greater zero. * @return {void} */ scrollTo : function(position) { this.assertNumber(position); }, /** * Scrolls by the given offset. * * This method automatically corrects the given position to respect * the {@link #maximum}. * * @param offset {Integer} Scroll by this offset * @return {void} */ scrollBy : function(offset) { this.assertNumber(offset); }, /** * Scrolls by the given number of steps. * * This method automatically corrects the given position to respect * the {@link #maximum}. * * @param steps {Integer} Number of steps * @return {void} */ scrollBySteps : function(steps) { this.assertNumber(steps); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's left-level directory for details. Authors: * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * The scroll bar widget wraps the native browser scroll bars as a qooxdoo widget. * It can be uses instead of the styled qooxdoo scroll bars. * * Scroll bars are used by the {@link qx.ui.container.Scroll} container. Usually * a scroll bar is not used directly. * * *Example* * * Here is a little example of how to use the widget. * * <pre class='javascript'> * var scrollBar = new qx.ui.core.scroll.NativeScrollBar("horizontal"); * scrollBar.set({ * maximum: 500 * }) * this.getRoot().add(scrollBar); * </pre> * * This example creates a horizontal scroll bar with a maximum value of 500. * * *External Documentation* * * <a href='http://manual.qooxdoo.org/${qxversion}/pages/widget/scrollbar.html' target='_blank'> * Documentation of this widget in the qooxdoo manual.</a> */ qx.Class.define("qx.ui.core.scroll.NativeScrollBar", { extend : qx.ui.core.Widget, implement : qx.ui.core.scroll.IScrollBar, /** * @param orientation {String?"horizontal"} The initial scroll bar orientation */ construct : function(orientation) { this.base(arguments); this.addState("native"); this.getContentElement().addListener("scroll", this._onScroll, this); this.addListener("mousedown", this._stopPropagation, this); this.addListener("mouseup", this._stopPropagation, this); this.addListener("mousemove", this._stopPropagation, this); this.addListener("appear", this._onAppear, this); this.getContentElement().add(this._getScrollPaneElement()); // Configure orientation if (orientation != null) { this.setOrientation(orientation); } else { this.initOrientation(); } }, properties : { // overridden appearance : { refine : true, init : "scrollbar" }, // interface implementation orientation : { check : [ "horizontal", "vertical" ], init : "horizontal", apply : "_applyOrientation" }, // interface implementation maximum : { check : "PositiveInteger", apply : "_applyMaximum", init : 100 }, // interface implementation position : { check : "Number", init : 0, apply : "_applyPosition", event : "scroll" }, /** * Step size for each click on the up/down or left/right buttons. */ singleStep : { check : "Integer", init : 20 }, // interface implementation knobFactor : { check : "PositiveNumber", nullable : true } }, members : { __isHorizontal : null, __scrollPaneElement : null, /** * Get the scroll pane html element. * * @return {qx.html.Element} The element */ _getScrollPaneElement : function() { if (!this.__scrollPaneElement) { this.__scrollPaneElement = new qx.html.Element(); } return this.__scrollPaneElement; }, /* --------------------------------------------------------------------------- WIDGET API --------------------------------------------------------------------------- */ // overridden renderLayout : function(left, top, width, height) { var changes = this.base(arguments, left, top, width, height); this._updateScrollBar(); return changes; }, // overridden _getContentHint : function() { var scrollbarWidth = qx.bom.element.Overflow.getScrollbarWidth(); return { width: this.__isHorizontal ? 100 : scrollbarWidth, maxWidth: this.__isHorizontal ? null : scrollbarWidth, minWidth: this.__isHorizontal ? null : scrollbarWidth, height: this.__isHorizontal ? scrollbarWidth : 100, maxHeight: this.__isHorizontal ? scrollbarWidth : null, minHeight: this.__isHorizontal ? scrollbarWidth : null } }, // overridden _applyEnabled : function(value, old) { this.base(arguments, value, old); this._updateScrollBar(); }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyMaximum : function(value) { this._updateScrollBar(); }, // property apply _applyPosition : function(value) { var content = this.getContentElement(); if (this.__isHorizontal) { content.scrollToX(value) } else { content.scrollToY(value); } }, // property apply _applyOrientation : function(value, old) { var isHorizontal = this.__isHorizontal = value === "horizontal"; this.set({ allowGrowX : isHorizontal, allowShrinkX : isHorizontal, allowGrowY : !isHorizontal, allowShrinkY : !isHorizontal }); if (isHorizontal) { this.replaceState("vertical", "horizontal"); } else { this.replaceState("horizontal", "vertical"); } this.getContentElement().setStyles({ overflowX: isHorizontal ? "scroll" : "hidden", overflowY: isHorizontal ? "hidden" : "scroll" }); // Update layout qx.ui.core.queue.Layout.add(this); }, /** * Update the scroll bar according to its current size, max value and * enabled state. */ _updateScrollBar : function() { var isHorizontal = this.__isHorizontal; var bounds = this.getBounds(); if (!bounds) { return; } if (this.isEnabled()) { var containerSize = isHorizontal ? bounds.width : bounds.height; var innerSize = this.getMaximum() + containerSize; } else { innerSize = 0; } // Scrollbars don't work properly in IE if the element with overflow has // excatly the size of the scrollbar. Thus we move the element one pixel // out of the view and increase the size by one. if ((qx.core.Environment.get("engine.name") == "mshtml")) { var bounds = this.getBounds(); this.getContentElement().setStyles({ left: isHorizontal ? "0" : "-1px", top: isHorizontal ? "-1px" : "0", width: (isHorizontal ? bounds.width : bounds.width + 1) + "px", height: (isHorizontal ? bounds.height + 1 : bounds.height) + "px" }); } this._getScrollPaneElement().setStyles({ left: 0, top: 0, width: (isHorizontal ? innerSize : 1) + "px", height: (isHorizontal ? 1 : innerSize) + "px" }); this.scrollTo(this.getPosition()); }, // interface implementation scrollTo : function(position) { this.setPosition(Math.max(0, Math.min(this.getMaximum(), position))); }, // interface implementation scrollBy : function(offset) { this.scrollTo(this.getPosition() + offset) }, // interface implementation scrollBySteps : function(steps) { var size = this.getSingleStep(); this.scrollBy(steps * size); }, /** * Scroll event handler * * @param e {qx.event.type.Event} the scroll event */ _onScroll : function(e) { var container = this.getContentElement(); var position = this.__isHorizontal ? container.getScrollX() : container.getScrollY(); this.setPosition(position); }, /** * Listener for appear which ensured the scroll bar is positioned right * on appear. * * @param e {qx.event.type.Data} Incoming event object */ _onAppear : function(e) { this._applyPosition(this.getPosition()); }, /** * Stops propagation on the given even * * @param e {qx.event.type.Event} the event */ _stopPropagation : function(e) { e.stopPropagation(); } }, destruct : function() { this._disposeObjects("__scrollPaneElement"); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's left-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * The scroll bar widget, is a special slider, which is used in qooxdoo instead * of the native browser scroll bars. * * Scroll bars are used by the {@link qx.ui.container.Scroll} container. Usually * a scroll bar is not used directly. * * @childControl slider {qx.ui.core.scroll.ScrollSlider} scroll slider component * @childControl button-begin {qx.ui.form.RepeatButton} button to scroll to top * @childControl button-end {qx.ui.form.RepeatButton} button to scroll to bottom * * *Example* * * Here is a little example of how to use the widget. * * <pre class='javascript'> * var scrollBar = new qx.ui.core.scroll.ScrollBar("horizontal"); * scrollBar.set({ * maximum: 500 * }) * this.getRoot().add(scrollBar); * </pre> * * This example creates a horizontal scroll bar with a maximum value of 500. * * *External Documentation* * * <a href='http://manual.qooxdoo.org/${qxversion}/pages/widget/scrollbar.html' target='_blank'> * Documentation of this widget in the qooxdoo manual.</a> */ qx.Class.define("qx.ui.core.scroll.ScrollBar", { extend : qx.ui.core.Widget, implement : qx.ui.core.scroll.IScrollBar, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param orientation {String?"horizontal"} The initial scroll bar orientation */ construct : function(orientation) { this.base(arguments); // Create child controls this._createChildControl("button-begin"); this._createChildControl("slider").addListener("resize", this._onResizeSlider, this); this._createChildControl("button-end"); // Configure orientation if (orientation != null) { this.setOrientation(orientation); } else { this.initOrientation(); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { // overridden appearance : { refine : true, init : "scrollbar" }, /** * The scroll bar orientation */ orientation : { check : [ "horizontal", "vertical" ], init : "horizontal", apply : "_applyOrientation" }, /** * The maximum value (difference between available size and * content size). */ maximum : { check : "PositiveInteger", apply : "_applyMaximum", init : 100 }, /** * Position of the scrollbar (which means the scroll left/top of the * attached area's pane) * * Strictly validates according to {@link #maximum}. * Does not apply any correction to the incoming value. If you depend * on this, please use {@link #scrollTo} instead. */ position : { check : "qx.lang.Type.isNumber(value)&&value>=0&&value<=this.getMaximum()", init : 0, apply : "_applyPosition", event : "scroll" }, /** * Step size for each click on the up/down or left/right buttons. */ singleStep : { check : "Integer", init : 20 }, /** * The amount to increment on each event. Typically corresponds * to the user pressing <code>PageUp</code> or <code>PageDown</code>. */ pageStep : { check : "Integer", init : 10, apply : "_applyPageStep" }, /** * Factor to apply to the width/height of the knob in relation * to the dimension of the underlying area. */ knobFactor : { check : "PositiveNumber", apply : "_applyKnobFactor", nullable : true } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __offset : 2, __originalMinSize : 0, // overridden _computeSizeHint : function() { var hint = this.base(arguments); if (this.getOrientation() === "horizontal") { this.__originalMinSize = hint.minWidth; hint.minWidth = 0; } else { this.__originalMinSize = hint.minHeight; hint.minHeight = 0; } return hint; }, // overridden renderLayout : function(left, top, width, height) { var changes = this.base(arguments, left, top, width, height); var horizontal = this.getOrientation() === "horizontal"; if (this.__originalMinSize >= (horizontal ? width : height)) { this.getChildControl("button-begin").setVisibility("hidden"); this.getChildControl("button-end").setVisibility("hidden"); } else { this.getChildControl("button-begin").setVisibility("visible"); this.getChildControl("button-end").setVisibility("visible"); } return changes }, // overridden _createChildControlImpl : function(id, hash) { var control; switch(id) { case "slider": control = new qx.ui.core.scroll.ScrollSlider(); control.setPageStep(100); control.setFocusable(false); control.addListener("changeValue", this._onChangeSliderValue, this); this._add(control, {flex: 1}); break; case "button-begin": // Top/Left Button control = new qx.ui.form.RepeatButton(); control.setFocusable(false); control.addListener("execute", this._onExecuteBegin, this); this._add(control); break; case "button-end": // Bottom/Right Button control = new qx.ui.form.RepeatButton(); control.setFocusable(false); control.addListener("execute", this._onExecuteEnd, this); this._add(control); break; } return control || this.base(arguments, id); }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyMaximum : function(value) { this.getChildControl("slider").setMaximum(value); }, // property apply _applyPosition : function(value) { this.getChildControl("slider").setValue(value); }, // property apply _applyKnobFactor : function(value) { this.getChildControl("slider").setKnobFactor(value); }, // property apply _applyPageStep : function(value) { this.getChildControl("slider").setPageStep(value); }, // property apply _applyOrientation : function(value, old) { // Dispose old layout var oldLayout = this._getLayout(); if (oldLayout) { oldLayout.dispose(); } // Reconfigure if (value === "horizontal") { this._setLayout(new qx.ui.layout.HBox()); this.setAllowStretchX(true); this.setAllowStretchY(false); this.replaceState("vertical", "horizontal"); this.getChildControl("button-begin").replaceState("up", "left"); this.getChildControl("button-end").replaceState("down", "right"); } else { this._setLayout(new qx.ui.layout.VBox()); this.setAllowStretchX(false); this.setAllowStretchY(true); this.replaceState("horizontal", "vertical"); this.getChildControl("button-begin").replaceState("left", "up"); this.getChildControl("button-end").replaceState("right", "down"); } // Sync slider orientation this.getChildControl("slider").setOrientation(value); }, /* --------------------------------------------------------------------------- METHOD REDIRECTION TO SLIDER --------------------------------------------------------------------------- */ /** * Scrolls to the given position. * * This method automatically corrects the given position to respect * the {@link #maximum}. * * @param position {Integer} Scroll to this position. Must be greater zero. * @return {void} */ scrollTo : function(position) { this.getChildControl("slider").slideTo(position); }, /** * Scrolls by the given offset. * * This method automatically corrects the given position to respect * the {@link #maximum}. * * @param offset {Integer} Scroll by this offset * @return {void} */ scrollBy : function(offset) { this.getChildControl("slider").slideBy(offset); }, /** * Scrolls by the given number of steps. * * This method automatically corrects the given position to respect * the {@link #maximum}. * * @param steps {Integer} Number of steps * @return {void} */ scrollBySteps : function(steps) { var size = this.getSingleStep(); this.getChildControl("slider").slideBy(steps * size); }, /* --------------------------------------------------------------------------- EVENT LISTENER --------------------------------------------------------------------------- */ /** * Executed when the up/left button is executed (pressed) * * @param e {qx.event.type.Event} Execute event of the button * @return {void} */ _onExecuteBegin : function(e) { this.scrollBy(-this.getSingleStep()); }, /** * Executed when the down/right button is executed (pressed) * * @param e {qx.event.type.Event} Execute event of the button * @return {void} */ _onExecuteEnd : function(e) { this.scrollBy(this.getSingleStep()); }, /** * Change listener for slider value changes. * * @param e {qx.event.type.Data} The change event object * @return {void} */ _onChangeSliderValue : function(e) { this.setPosition(e.getData()); }, /** * Hide the knob of the slider if the slidebar is too small or show it * otherwise. * * @param e {qx.event.type.Data} event object */ _onResizeSlider : function(e) { var knob = this.getChildControl("slider").getChildControl("knob"); var knobHint = knob.getSizeHint(); var hideKnob = false; var sliderSize = this.getChildControl("slider").getInnerSize(); if (this.getOrientation() == "vertical") { if (sliderSize.height < knobHint.minHeight + this.__offset) { hideKnob = true; } } else { if (sliderSize.width < knobHint.minWidth + this.__offset) { hideKnob = true; } } if (hideKnob) { knob.exclude(); } else { knob.show(); } } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's left-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * The Slider widget provides a vertical or horizontal slider. * * The Slider is the classic widget for controlling a bounded value. * It lets the user move a slider handle along a horizontal or vertical * groove and translates the handle's position into an integer value * within the defined range. * * The Slider has very few of its own functions. * The most useful functions are slideTo() to set the slider directly to some * value; setSingleStep(), setPageStep() to set the steps; and setMinimum() * and setMaximum() to define the range of the slider. * * A slider accepts focus on Tab and provides both a mouse wheel and * a keyboard interface. The keyboard interface is the following: * * * Left/Right move a horizontal slider by one single step. * * Up/Down move a vertical slider by one single step. * * PageUp moves up one page. * * PageDown moves down one page. * * Home moves to the start (minimum). * * End moves to the end (maximum). * * Here are the main properties of the class: * * # <code>value</code>: The bounded integer that {@link qx.ui.form.INumberForm} * maintains. * # <code>minimum</code>: The lowest possible value. * # <code>maximum</code>: The highest possible value. * # <code>singleStep</code>: The smaller of two natural steps that an abstract * sliders provides and typically corresponds to the user pressing an arrow key. * # <code>pageStep</code>: The larger of two natural steps that an abstract * slider provides and typically corresponds to the user pressing PageUp or * PageDown. * * @childControl knob {qx.ui.core.Widget} knob to set the value of the slider */ qx.Class.define("qx.ui.form.Slider", { extend : qx.ui.core.Widget, implement : [ qx.ui.form.IForm, qx.ui.form.INumberForm, qx.ui.form.IRange ], include : [qx.ui.form.MForm], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param orientation {String?"horizontal"} Configure the * {@link #orientation} property */ construct : function(orientation) { this.base(arguments); // Force canvas layout this._setLayout(new qx.ui.layout.Canvas()); // Add listeners this.addListener("keypress", this._onKeyPress); this.addListener("mousewheel", this._onMouseWheel); this.addListener("mousedown", this._onMouseDown); this.addListener("mouseup", this._onMouseUp); this.addListener("losecapture", this._onMouseUp); this.addListener("resize", this._onUpdate); // Stop events this.addListener("contextmenu", this._onStopEvent); this.addListener("click", this._onStopEvent); this.addListener("dblclick", this._onStopEvent); // Initialize orientation if (orientation != null) { this.setOrientation(orientation); } else { this.initOrientation(); } }, /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** * Change event for the value. */ changeValue: 'qx.event.type.Data' }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { // overridden appearance : { refine : true, init : "slider" }, // overridden focusable : { refine : true, init : true }, /** Whether the slider is horizontal or vertical. */ orientation : { check : [ "horizontal", "vertical" ], init : "horizontal", apply : "_applyOrientation" }, /** * The current slider value. * * Strictly validates according to {@link #minimum} and {@link #maximum}. * Do not apply any value correction to the incoming value. If you depend * on this, please use {@link #slideTo} instead. */ value : { check : "typeof value==='number'&&value>=this.getMinimum()&&value<=this.getMaximum()", init : 0, apply : "_applyValue", nullable: true }, /** * The minimum slider value (may be negative). This value must be smaller * than {@link #maximum}. */ minimum : { check : "Integer", init : 0, apply : "_applyMinimum", event: "changeMinimum" }, /** * The maximum slider value (may be negative). This value must be larger * than {@link #minimum}. */ maximum : { check : "Integer", init : 100, apply : "_applyMaximum", event : "changeMaximum" }, /** * The amount to increment on each event. Typically corresponds * to the user pressing an arrow key. */ singleStep : { check : "Integer", init : 1 }, /** * The amount to increment on each event. Typically corresponds * to the user pressing <code>PageUp</code> or <code>PageDown</code>. */ pageStep : { check : "Integer", init : 10 }, /** * Factor to apply to the width/height of the knob in relation * to the dimension of the underlying area. */ knobFactor : { check : "Number", apply : "_applyKnobFactor", nullable : true } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __sliderLocation : null, __knobLocation : null, __knobSize : null, __dragMode : null, __dragOffset : null, __trackingMode : null, __trackingDirection : null, __trackingEnd : null, __timer : null, // event delay stuff during drag __dragTimer: null, __lastValueEvent: null, __dragValue: null, // overridden /** * @lint ignoreReferenceField(_forwardStates) */ _forwardStates : { invalid : true }, // overridden _createChildControlImpl : function(id, hash) { var control; switch(id) { case "knob": control = new qx.ui.core.Widget(); control.addListener("resize", this._onUpdate, this); control.addListener("mouseover", this._onMouseOver); control.addListener("mouseout", this._onMouseOut); this._add(control); break; } return control || this.base(arguments, id); }, /* --------------------------------------------------------------------------- EVENT HANDLER --------------------------------------------------------------------------- */ /** * Event handler for mouseover events at the knob child control. * * Adds the 'hovered' state * * @param e {qx.event.type.Mouse} Incoming mouse event */ _onMouseOver : function(e) { this.addState("hovered"); }, /** * Event handler for mouseout events at the knob child control. * * Removes the 'hovered' state * * @param e {qx.event.type.Mouse} Incoming mouse event */ _onMouseOut : function(e) { this.removeState("hovered"); }, /** * Listener of mousewheel event * * @param e {qx.event.type.Mouse} Incoming event object * @return {void} */ _onMouseWheel : function(e) { var axis = this.getOrientation() === "horizontal" ? "x" : "y"; var delta = e.getWheelDelta(axis); var direction = delta > 0 ? 1 : delta < 0 ? -1 : 0; this.slideBy(direction * this.getSingleStep()); e.stop(); }, /** * Event handler for keypress events. * * Adds support for arrow keys, page up, page down, home and end keys. * * @param e {qx.event.type.KeySequence} Incoming keypress event * @return {void} */ _onKeyPress : function(e) { var isHorizontal = this.getOrientation() === "horizontal"; var backward = isHorizontal ? "Left" : "Up"; var forward = isHorizontal ? "Right" : "Down"; switch(e.getKeyIdentifier()) { case forward: this.slideForward(); break; case backward: this.slideBack(); break; case "PageDown": this.slidePageForward(); break; case "PageUp": this.slidePageBack(); break; case "Home": this.slideToBegin(); break; case "End": this.slideToEnd(); break; default: return; } // Stop processed events e.stop(); }, /** * Listener of mousedown event. Initializes drag or tracking mode. * * @param e {qx.event.type.Mouse} Incoming event object * @return {void} */ _onMouseDown : function(e) { // this can happen if the user releases the button while dragging outside // of the browser viewport if (this.__dragMode) { return; } var isHorizontal = this.__isHorizontal; var knob = this.getChildControl("knob"); var locationProperty = isHorizontal ? "left" : "top"; var cursorLocation = isHorizontal ? e.getDocumentLeft() : e.getDocumentTop(); var sliderLocation = this.__sliderLocation = qx.bom.element.Location.get(this.getContentElement().getDomElement())[locationProperty]; var knobLocation = this.__knobLocation = qx.bom.element.Location.get(knob.getContainerElement().getDomElement())[locationProperty]; if (e.getTarget() === knob) { // Switch into drag mode this.__dragMode = true; if (!this.__dragTimer){ // create a timer to fire delayed dragging events if dragging stops. this.__dragTimer = new qx.event.Timer(100); this.__dragTimer.addListener("interval", this._fireValue, this); } this.__dragTimer.start(); // Compute dragOffset (includes both: inner position of the widget and // cursor position on knob) this.__dragOffset = cursorLocation + sliderLocation - knobLocation; // add state knob.addState("pressed"); } else { // Switch into tracking mode this.__trackingMode = true; // Detect tracking direction this.__trackingDirection = cursorLocation <= knobLocation ? -1 : 1; // Compute end value this.__computeTrackingEnd(e); // Directly call interval method once this._onInterval(); // Initialize timer (when needed) if (!this.__timer) { this.__timer = new qx.event.Timer(100); this.__timer.addListener("interval", this._onInterval, this); } // Start timer this.__timer.start(); } // Register move listener this.addListener("mousemove", this._onMouseMove); // Activate capturing this.capture(); // Stop event e.stopPropagation(); }, /** * Listener of mouseup event. Used for cleanup of previously * initialized modes. * * @param e {qx.event.type.Mouse} Incoming event object * @return {void} */ _onMouseUp : function(e) { if (this.__dragMode) { // Release capture mode this.releaseCapture(); // Cleanup status flags delete this.__dragMode; // as we come out of drag mode, make // sure content gets synced this.__dragTimer.stop(); this._fireValue(); delete this.__dragOffset; // remove state this.getChildControl("knob").removeState("pressed"); // it's necessary to check whether the mouse cursor is over the knob widget to be able to // to decide whether to remove the 'hovered' state. if (e.getType() === "mouseup") { var deltaSlider; var deltaPosition; var positionSlider; if (this.__isHorizontal) { deltaSlider = e.getDocumentLeft() - (this._valueToPosition(this.getValue()) + this.__sliderLocation); positionSlider = qx.bom.element.Location.get(this.getContentElement().getDomElement())["top"]; deltaPosition = e.getDocumentTop() - (positionSlider + this.getChildControl("knob").getBounds().top); } else { deltaSlider = e.getDocumentTop() - (this._valueToPosition(this.getValue()) + this.__sliderLocation); positionSlider = qx.bom.element.Location.get(this.getContentElement().getDomElement())["left"]; deltaPosition = e.getDocumentLeft() - (positionSlider + this.getChildControl("knob").getBounds().left); } if (deltaPosition < 0 || deltaPosition > this.__knobSize || deltaSlider < 0 || deltaSlider > this.__knobSize) { this.getChildControl("knob").removeState("hovered"); } } } else if (this.__trackingMode) { // Stop timer interval this.__timer.stop(); // Release capture mode this.releaseCapture(); // Cleanup status flags delete this.__trackingMode; delete this.__trackingDirection; delete this.__trackingEnd; } // Remove move listener again this.removeListener("mousemove", this._onMouseMove); // Stop event if (e.getType() === "mouseup") { e.stopPropagation(); } }, /** * Listener of mousemove event for the knob. Only used in drag mode. * * @param e {qx.event.type.Mouse} Incoming event object * @return {void} */ _onMouseMove : function(e) { if (this.__dragMode) { var dragStop = this.__isHorizontal ? e.getDocumentLeft() : e.getDocumentTop(); var position = dragStop - this.__dragOffset; this.slideTo(this._positionToValue(position)); } else if (this.__trackingMode) { // Update tracking end on mousemove this.__computeTrackingEnd(e); } // Stop event e.stopPropagation(); }, /** * Listener of interval event by the internal timer. Only used * in tracking sequences. * * @param e {qx.event.type.Event} Incoming event object * @return {void} */ _onInterval : function(e) { // Compute new value var value = this.getValue() + (this.__trackingDirection * this.getPageStep()); // Limit value if (value < this.getMinimum()) { value = this.getMinimum(); } else if (value > this.getMaximum()) { value = this.getMaximum(); } // Stop at tracking position (where the mouse is pressed down) var slideBack = this.__trackingDirection == -1; if ((slideBack && value <= this.__trackingEnd) || (!slideBack && value >= this.__trackingEnd)) { value = this.__trackingEnd; } // Finally slide to the desired position this.slideTo(value); }, /** * Listener of resize event for both the slider itself and the knob. * * @param e {qx.event.type.Data} Incoming event object * @return {void} */ _onUpdate : function(e) { // Update sliding space var availSize = this.getInnerSize(); var knobSize = this.getChildControl("knob").getBounds(); var sizeProperty = this.__isHorizontal ? "width" : "height"; // Sync knob size this._updateKnobSize(); // Store knob size this.__slidingSpace = availSize[sizeProperty] - knobSize[sizeProperty]; this.__knobSize = knobSize[sizeProperty]; // Update knob position (sliding space must be updated first) this._updateKnobPosition(); }, /* --------------------------------------------------------------------------- UTILS --------------------------------------------------------------------------- */ /** {Boolean} Whether the slider is laid out horizontally */ __isHorizontal : false, /** * {Integer} Available space for knob to slide on, computed on resize of * the widget */ __slidingSpace : 0, /** * Computes the value where the tracking should end depending on * the current mouse position. * * @param e {qx.event.type.Mouse} Incoming mouse event * @return {void} */ __computeTrackingEnd : function(e) { var isHorizontal = this.__isHorizontal; var cursorLocation = isHorizontal ? e.getDocumentLeft() : e.getDocumentTop(); var sliderLocation = this.__sliderLocation; var knobLocation = this.__knobLocation; var knobSize = this.__knobSize; // Compute relative position var position = cursorLocation - sliderLocation; if (cursorLocation >= knobLocation) { position -= knobSize; } // Compute stop value var value = this._positionToValue(position); var min = this.getMinimum(); var max = this.getMaximum(); if (value < min) { value = min; } else if (value > max) { value = max; } else { var old = this.getValue(); var step = this.getPageStep(); var method = this.__trackingDirection < 0 ? "floor" : "ceil"; // Fix to page step value = old + (Math[method]((value - old) / step) * step); } // Store value when undefined, otherwise only when it follows the // current direction e.g. goes up or down if (this.__trackingEnd == null || (this.__trackingDirection == -1 && value <= this.__trackingEnd) || (this.__trackingDirection == 1 && value >= this.__trackingEnd)) { this.__trackingEnd = value; } }, /** * Converts the given position to a value. * * Does not respect single or page step. * * @param position {Integer} Position to use * @return {Integer} Resulting value (rounded) */ _positionToValue : function(position) { // Reading available space var avail = this.__slidingSpace; // Protect undefined value (before initial resize) and division by zero if (avail == null || avail == 0) { return 0; } // Compute and limit percent var percent = position / avail; if (percent < 0) { percent = 0; } else if (percent > 1) { percent = 1; } // Compute range var range = this.getMaximum() - this.getMinimum(); // Compute value return this.getMinimum() + Math.round(range * percent); }, /** * Converts the given value to a position to place * the knob to. * * @param value {Integer} Value to use * @return {Integer} Computed position (rounded) */ _valueToPosition : function(value) { // Reading available space var avail = this.__slidingSpace; if (avail == null) { return 0; } // Computing range var range = this.getMaximum() - this.getMinimum(); // Protect division by zero if (range == 0) { return 0; } // Translating value to distance from minimum var value = value - this.getMinimum(); // Compute and limit percent var percent = value / range; if (percent < 0) { percent = 0; } else if (percent > 1) { percent = 1; } // Compute position from available space and percent return Math.round(avail * percent); }, /** * Updates the knob position following the currently configured * value. Useful on reflows where the dimensions of the slider * itself have been modified. * * @return {void} */ _updateKnobPosition : function() { this._setKnobPosition(this._valueToPosition(this.getValue())); }, /** * Moves the knob to the given position. * * @param position {Integer} Any valid position (needs to be * greater or equal than zero) * @return {void} */ _setKnobPosition : function(position) { // Use DOM Element var container = this.getChildControl("knob").getContainerElement(); if (this.__isHorizontal) { container.setStyle("left", position+"px", true); } else { container.setStyle("top", position+"px", true); } // Alternative: Use layout system // Not used because especially in IE7/Firefox2 the // direct element manipulation is a lot faster /* if (this.__isHorizontal) { this.getChildControl("knob").setLayoutProperties({left:position}); } else { this.getChildControl("knob").setLayoutProperties({top:position}); } */ }, /** * Reconfigures the size of the knob depending on * the optionally defined {@link #knobFactor}. * * @return {void} */ _updateKnobSize : function() { // Compute knob size var knobFactor = this.getKnobFactor(); if (knobFactor == null) { return; } // Ignore when not rendered yet var avail = this.getInnerSize(); if (avail == null) { return; } // Read size property if (this.__isHorizontal) { this.getChildControl("knob").setWidth(Math.round(knobFactor * avail.width)); } else { this.getChildControl("knob").setHeight(Math.round(knobFactor * avail.height)); } }, /* --------------------------------------------------------------------------- SLIDE METHODS --------------------------------------------------------------------------- */ /** * Slides backward to the minimum value * * @return {void} */ slideToBegin : function() { this.slideTo(this.getMinimum()); }, /** * Slides forward to the maximum value * * @return {void} */ slideToEnd : function() { this.slideTo(this.getMaximum()); }, /** * Slides forward (right or bottom depending on orientation) * * @return {void} */ slideForward : function() { this.slideBy(this.getSingleStep()); }, /** * Slides backward (to left or top depending on orientation) * * @return {void} */ slideBack : function() { this.slideBy(-this.getSingleStep()); }, /** * Slides a page forward (to right or bottom depending on orientation) * * @return {void} */ slidePageForward : function() { this.slideBy(this.getPageStep()); }, /** * Slides a page backward (to left or top depending on orientation) * * @return {void} */ slidePageBack : function() { this.slideBy(-this.getPageStep()); }, /** * Slides by the given offset. * * This method works with the value, not with the coordinate. * * @param offset {Integer} Offset to scroll by * @return {void} */ slideBy : function(offset) { this.slideTo(this.getValue() + offset); }, /** * Slides to the given value * * This method works with the value, not with the coordinate. * * @param value {Integer} Scroll to a value between the defined * minimum and maximum. * @return {void} */ slideTo : function(value) { // Bring into allowed range or fix to single step grid if (value < this.getMinimum()) { value = this.getMinimum(); } else if (value > this.getMaximum()) { value = this.getMaximum(); } else { value = this.getMinimum() + Math.round((value - this.getMinimum()) / this.getSingleStep()) * this.getSingleStep() } // Sync with property this.setValue(value); }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyOrientation : function(value, old) { var knob = this.getChildControl("knob"); // Update private flag for faster access this.__isHorizontal = value === "horizontal"; // Toggle states and knob layout if (this.__isHorizontal) { this.removeState("vertical"); knob.removeState("vertical"); this.addState("horizontal"); knob.addState("horizontal"); knob.setLayoutProperties({top:0, right:null, bottom:0}); } else { this.removeState("horizontal"); knob.removeState("horizontal"); this.addState("vertical"); knob.addState("vertical"); knob.setLayoutProperties({right:0, bottom:null, left:0}); } // Sync knob position this._updateKnobPosition(); }, // property apply _applyKnobFactor : function(value, old) { if (value != null) { this._updateKnobSize(); } else { if (this.__isHorizontal) { this.getChildControl("knob").resetWidth(); } else { this.getChildControl("knob").resetHeight(); } } }, // property apply _applyValue : function(value, old) { if (value != null) { this._updateKnobPosition(); if (this.__dragMode) { this.__dragValue = [value,old]; } else { this.fireEvent("changeValue", qx.event.type.Data, [value,old]); } } else { this.resetValue(); } }, /** * Helper for applyValue which fires the changeValue event. */ _fireValue: function(){ if (!this.__dragValue){ return; } var tmp = this.__dragValue; this.__dragValue = null; this.fireEvent("changeValue", qx.event.type.Data, tmp); }, // property apply _applyMinimum : function(value, old) { if (this.getValue() < value) { this.setValue(value); } this._updateKnobPosition(); }, // property apply _applyMaximum : function(value, old) { if (this.getValue() > value) { this.setValue(value); } this._updateKnobPosition(); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's left-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * Minimal modified version of the {@link qx.ui.form.Slider} to be * used by {@link qx.ui.core.scroll.ScrollBar}. * * @internal */ qx.Class.define("qx.ui.core.scroll.ScrollSlider", { extend : qx.ui.form.Slider, // overridden construct : function(orientation) { this.base(arguments, orientation); // Remove mousewheel/keypress events this.removeListener("keypress", this._onKeyPress); this.removeListener("mousewheel", this._onMouseWheel); }, members : { // overridden getSizeHint : function(compute) { // get the original size hint var hint = this.base(arguments); // set the width or height to 0 depending on the orientation. // this is necessary to prevent the ScrollSlider to change the size // hint of its parent, which can cause errors on outer flex layouts // [BUG #3279] if (this.getOrientation() === "horizontal") { hint.width = 0; } else { hint.height = 0; } return hint; } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A horizontal box layout. * * The horizontal box layout lays out widgets in a horizontal row, from left * to right. * * *Features* * * * Minimum and maximum dimensions * * Prioritized growing/shrinking (flex) * * Margins (with horizontal collapsing) * * Auto sizing (ignoring percent values) * * Percent widths (not relevant for size hint) * * Alignment (child property {@link qx.ui.core.LayoutItem#alignX} is ignored) * * Horizontal spacing (collapsed with margins) * * Reversed children layout (from last to first) * * Vertical children stretching (respecting size hints) * * *Item Properties* * * <ul> * <li><strong>flex</strong> <em>(Integer)</em>: The flexibility of a layout item determines how the container * distributes remaining empty space among its children. If items are made * flexible, they can grow or shrink accordingly. Their relative flex values * determine how the items are being resized, i.e. the larger the flex ratio * of two items, the larger the resizing of the first item compared to the * second. * * If there is only one flex item in a layout container, its actual flex * value is not relevant. To disallow items to become flexible, set the * flex value to zero. * </li> * <li><strong>width</strong> <em>(String)</em>: Allows to define a percent * width for the item. The width in percent, if specified, is used instead * of the width defined by the size hint. The minimum and maximum width still * takes care of the element's limits. It has no influence on the layout's * size hint. Percent values are mostly useful for widgets which are sized by * the outer hierarchy. * </li> * </ul> * * *Example* * * Here is a little example of how to use the grid layout. * * <pre class="javascript"> * var layout = new qx.ui.layout.HBox(); * layout.setSpacing(4); // apply spacing * * var container = new qx.ui.container.Composite(layout); * * container.add(new qx.ui.core.Widget()); * container.add(new qx.ui.core.Widget()); * container.add(new qx.ui.core.Widget()); * </pre> * * *External Documentation* * * See <a href='http://manual.qooxdoo.org/${qxversion}/pages/layout/box.html'>extended documentation</a> * and links to demos for this layout. * */ qx.Class.define("qx.ui.layout.HBox", { extend : qx.ui.layout.Abstract, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param spacing {Integer?0} The spacing between child widgets {@link #spacing}. * @param alignX {String?"left"} Horizontal alignment of the whole children * block {@link #alignX}. * @param separator {Decorator} A separator to render between the items */ construct : function(spacing, alignX, separator) { this.base(arguments); if (spacing) { this.setSpacing(spacing); } if (alignX) { this.setAlignX(alignX); } if (separator) { this.setSeparator(separator); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * Horizontal alignment of the whole children block. The horizontal * alignment of the child is completely ignored in HBoxes ( * {@link qx.ui.core.LayoutItem#alignX}). */ alignX : { check : [ "left", "center", "right" ], init : "left", apply : "_applyLayoutChange" }, /** * Vertical alignment of each child. Can be overridden through * {@link qx.ui.core.LayoutItem#alignY}. */ alignY : { check : [ "top", "middle", "bottom" ], init : "top", apply : "_applyLayoutChange" }, /** Horizontal spacing between two children */ spacing : { check : "Integer", init : 0, apply : "_applyLayoutChange" }, /** Separator lines to use between the objects */ separator : { check : "Decorator", nullable : true, apply : "_applyLayoutChange" }, /** Whether the actual children list should be laid out in reversed order. */ reversed : { check : "Boolean", init : false, apply : "_applyReversed" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __widths : null, __flexs : null, __enableFlex : null, __children : null, /* --------------------------------------------------------------------------- HELPER METHODS --------------------------------------------------------------------------- */ // property apply _applyReversed : function() { // easiest way is to invalidate the cache this._invalidChildrenCache = true; // call normal layout change this._applyLayoutChange(); }, /** * Rebuilds caches for flex and percent layout properties */ __rebuildCache : function() { var children = this._getLayoutChildren(); var length = children.length; var enableFlex = false; var reuse = this.__widths && this.__widths.length != length && this.__flexs && this.__widths; var props; // Sparse array (keep old one if lengths has not been modified) var widths = reuse ? this.__widths : new Array(length); var flexs = reuse ? this.__flexs : new Array(length); // Reverse support if (this.getReversed()) { children = children.concat().reverse(); } // Loop through children to preparse values for (var i=0; i<length; i++) { props = children[i].getLayoutProperties(); if (props.width != null) { widths[i] = parseFloat(props.width) / 100; } if (props.flex != null) { flexs[i] = props.flex; enableFlex = true; } else { // reset (in case the index of the children changed: BUG #3131) flexs[i] = 0; } } // Store data if (!reuse) { this.__widths = widths; this.__flexs = flexs; } this.__enableFlex = enableFlex this.__children = children; // Clear invalidation marker delete this._invalidChildrenCache; }, /* --------------------------------------------------------------------------- LAYOUT INTERFACE --------------------------------------------------------------------------- */ // overridden verifyLayoutProperty : qx.core.Environment.select("qx.debug", { "true" : function(item, name, value) { this.assert(name === "flex" || name === "width", "The property '"+name+"' is not supported by the HBox layout!"); if (name =="width") { this.assertMatch(value, qx.ui.layout.Util.PERCENT_VALUE); } else { // flex this.assertNumber(value); this.assert(value >= 0); } }, "false" : null }), // overridden renderLayout : function(availWidth, availHeight) { // Rebuild flex/width caches if (this._invalidChildrenCache) { this.__rebuildCache(); } // Cache children var children = this.__children; var length = children.length; var util = qx.ui.layout.Util; // Compute gaps var spacing = this.getSpacing(); var separator = this.getSeparator(); if (separator) { var gaps = util.computeHorizontalSeparatorGaps(children, spacing, separator); } else { var gaps = util.computeHorizontalGaps(children, spacing, true); } // First run to cache children data and compute allocated width var i, child, width, percent; var widths = []; var allocatedWidth = gaps; for (i=0; i<length; i+=1) { percent = this.__widths[i]; width = percent != null ? Math.floor((availWidth - gaps) * percent) : children[i].getSizeHint().width; widths.push(width); allocatedWidth += width; } // Flex support (growing/shrinking) if (this.__enableFlex && allocatedWidth != availWidth) { var flexibles = {}; var flex, offset; for (i=0; i<length; i+=1) { flex = this.__flexs[i]; if (flex > 0) { hint = children[i].getSizeHint(); flexibles[i]= { min : hint.minWidth, value : widths[i], max : hint.maxWidth, flex : flex }; } } var result = util.computeFlexOffsets(flexibles, availWidth, allocatedWidth); for (i in result) { offset = result[i].offset; widths[i] += offset; allocatedWidth += offset; } } // Start with left coordinate var left = children[0].getMarginLeft(); // Alignment support if (allocatedWidth < availWidth && this.getAlignX() != "left") { left = availWidth - allocatedWidth; if (this.getAlignX() === "center") { left = Math.round(left / 2); } } // Layouting children var hint, top, height, width, marginRight, marginTop, marginBottom; var spacing = this.getSpacing(); // Pre configure separators this._clearSeparators(); // Compute separator width if (separator) { var separatorInsets = qx.theme.manager.Decoration.getInstance().resolve(separator).getInsets(); var separatorWidth = separatorInsets.left + separatorInsets.right; } // Render children and separators for (i=0; i<length; i+=1) { child = children[i]; width = widths[i]; hint = child.getSizeHint(); marginTop = child.getMarginTop(); marginBottom = child.getMarginBottom(); // Find usable height height = Math.max(hint.minHeight, Math.min(availHeight-marginTop-marginBottom, hint.maxHeight)); // Respect vertical alignment top = util.computeVerticalAlignOffset(child.getAlignY()||this.getAlignY(), height, availHeight, marginTop, marginBottom); // Add collapsed margin if (i > 0) { // Whether a separator has been configured if (separator) { // add margin of last child and spacing left += marginRight + spacing; // then render the separator at this position this._renderSeparator(separator, { left : left, top : 0, width : separatorWidth, height : availHeight }); // and finally add the size of the separator, the spacing (again) and the left margin left += separatorWidth + spacing + child.getMarginLeft(); } else { // Support margin collapsing when no separator is defined left += util.collapseMargins(spacing, marginRight, child.getMarginLeft()); } } // Layout child child.renderLayout(left, top, width, height); // Add width left += width; // Remember right margin (for collapsing) marginRight = child.getMarginRight(); } }, // overridden _computeSizeHint : function() { // Rebuild flex/width caches if (this._invalidChildrenCache) { this.__rebuildCache(); } var util = qx.ui.layout.Util; var children = this.__children; // Initialize var minWidth=0, width=0, percentMinWidth=0; var minHeight=0, height=0; var child, hint, margin; // Iterate over children for (var i=0, l=children.length; i<l; i+=1) { child = children[i]; hint = child.getSizeHint(); // Sum up widths width += hint.width; // Detect if child is shrinkable or has percent width and update minWidth var flex = this.__flexs[i]; var percent = this.__widths[i]; if (flex) { minWidth += hint.minWidth; } else if (percent) { percentMinWidth = Math.max(percentMinWidth, Math.round(hint.minWidth/percent)); } else { minWidth += hint.width; } // Build vertical margin sum margin = child.getMarginTop() + child.getMarginBottom(); // Find biggest height if ((hint.height+margin) > height) { height = hint.height + margin; } // Find biggest minHeight if ((hint.minHeight+margin) > minHeight) { minHeight = hint.minHeight + margin; } } minWidth += percentMinWidth; // Respect gaps var spacing = this.getSpacing(); var separator = this.getSeparator(); if (separator) { var gaps = util.computeHorizontalSeparatorGaps(children, spacing, separator); } else { var gaps = util.computeHorizontalGaps(children, spacing, true); } // Return hint return { minWidth : minWidth + gaps, width : width + gaps, minHeight : minHeight, height : height }; } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this.__widths = this.__flexs = this.__children = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's left-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * The ScrollArea provides a container widget with on demand scroll bars * if the content size exceeds the size of the container. * * @childControl pane {qx.ui.core.scroll.ScrollPane} pane which holds the content to scroll * @childControl scrollbar-x {qx.ui.core.scroll.ScrollBar?qx.ui.core.scroll.NativeScrollBar} horizontal scrollbar * @childControl scrollbar-y {qx.ui.core.scroll.ScrollBar?qx.ui.core.scroll.NativeScrollBar} vertical scrollbar * @childControl corner {qx.ui.core.Widget} corner where no scrollbar is shown */ qx.Class.define("qx.ui.core.scroll.AbstractScrollArea", { extend : qx.ui.core.Widget, include : [ qx.ui.core.scroll.MScrollBarFactory, qx.ui.core.scroll.MWheelHandling ], type : "abstract", /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ construct : function() { this.base(arguments); if (qx.core.Environment.get("os.scrollBarOverlayed")) { // use a plain canvas to overlay the scroll bars this._setLayout(new qx.ui.layout.Canvas()); } else { // Create 'fixed' grid layout var grid = new qx.ui.layout.Grid(); grid.setColumnFlex(0, 1); grid.setRowFlex(0, 1); this._setLayout(grid); } // Mousewheel listener to scroll vertically this.addListener("mousewheel", this._onMouseWheel, this); // touch support if (qx.core.Environment.get("event.touch")) { // touch move listener for touch scrolling this.addListener("touchmove", this._onTouchMove, this); // reset the delta on every touch session this.addListener("touchstart", function() { this.__old = {"x": 0, "y": 0}; }, this); this.__old = {}; this.__impulseTimerId = {}; } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { // overridden appearance : { refine : true, init : "scrollarea" }, // overridden width : { refine : true, init : 100 }, // overridden height : { refine : true, init : 200 }, /** * The policy, when the horizontal scrollbar should be shown. * <ul> * <li><b>auto</b>: Show scrollbar on demand</li> * <li><b>on</b>: Always show the scrollbar</li> * <li><b>off</b>: Never show the scrollbar</li> * </ul> */ scrollbarX : { check : ["auto", "on", "off"], init : "auto", themeable : true, apply : "_computeScrollbars" }, /** * The policy, when the horizontal scrollbar should be shown. * <ul> * <li><b>auto</b>: Show scrollbar on demand</li> * <li><b>on</b>: Always show the scrollbar</li> * <li><b>off</b>: Never show the scrollbar</li> * </ul> */ scrollbarY : { check : ["auto", "on", "off"], init : "auto", themeable : true, apply : "_computeScrollbars" }, /** * Group property, to set the overflow of both scroll bars. */ scrollbar : { group : [ "scrollbarX", "scrollbarY" ] } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __old : null, __impulseTimerId : null, /* --------------------------------------------------------------------------- CHILD CONTROL SUPPORT --------------------------------------------------------------------------- */ // overridden _createChildControlImpl : function(id, hash) { var control; switch(id) { case "pane": control = new qx.ui.core.scroll.ScrollPane(); control.addListener("update", this._computeScrollbars, this); control.addListener("scrollX", this._onScrollPaneX, this); control.addListener("scrollY", this._onScrollPaneY, this); if (qx.core.Environment.get("os.scrollBarOverlayed")) { this._add(control, {edge: 0}); } else { this._add(control, {row: 0, column: 0}); } break; case "scrollbar-x": control = this._createScrollBar("horizontal"); control.setMinWidth(0); control.exclude(); control.addListener("scroll", this._onScrollBarX, this); control.addListener("changeVisibility", this._onChangeScrollbarXVisibility, this); if (qx.core.Environment.get("os.scrollBarOverlayed")) { control.setMinHeight(qx.bom.element.Overflow.DEFAULT_SCROLLBAR_WIDTH); this._add(control, {bottom: 0, right: 0, left: 0}); } else { this._add(control, {row: 1, column: 0}); } break; case "scrollbar-y": control = this._createScrollBar("vertical"); control.setMinHeight(0); control.exclude(); control.addListener("scroll", this._onScrollBarY, this); control.addListener("changeVisibility", this._onChangeScrollbarYVisibility, this); if (qx.core.Environment.get("os.scrollBarOverlayed")) { control.setMinWidth(qx.bom.element.Overflow.DEFAULT_SCROLLBAR_WIDTH); this._add(control, {right: 0, bottom: 0, top: 0}); } else { this._add(control, {row: 0, column: 1}); } break; case "corner": control = new qx.ui.core.Widget(); control.setWidth(0); control.setHeight(0); control.exclude(); if (!qx.core.Environment.get("os.scrollBarOverlayed")) { // only add for non overlayed scroll bars this._add(control, {row: 1, column: 1}); } break; } return control || this.base(arguments, id); }, /* --------------------------------------------------------------------------- PANE SIZE --------------------------------------------------------------------------- */ /** * Returns the boundaries of the pane. * * @return {Map} The pane boundaries. */ getPaneSize : function() { return this.getChildControl("pane").getInnerSize(); }, /* --------------------------------------------------------------------------- ITEM LOCATION SUPPORT --------------------------------------------------------------------------- */ /** * Returns the top offset of the given item in relation to the * inner height of this widget. * * @param item {qx.ui.core.Widget} Item to query * @return {Integer} Top offset */ getItemTop : function(item) { return this.getChildControl("pane").getItemTop(item); }, /** * Returns the top offset of the end of the given item in relation to the * inner height of this widget. * * @param item {qx.ui.core.Widget} Item to query * @return {Integer} Top offset */ getItemBottom : function(item) { return this.getChildControl("pane").getItemBottom(item); }, /** * Returns the left offset of the given item in relation to the * inner width of this widget. * * @param item {qx.ui.core.Widget} Item to query * @return {Integer} Top offset */ getItemLeft : function(item) { return this.getChildControl("pane").getItemLeft(item); }, /** * Returns the left offset of the end of the given item in relation to the * inner width of this widget. * * @param item {qx.ui.core.Widget} Item to query * @return {Integer} Right offset */ getItemRight : function(item) { return this.getChildControl("pane").getItemRight(item); }, /* --------------------------------------------------------------------------- SCROLL SUPPORT --------------------------------------------------------------------------- */ /** * Scrolls the element's content to the given left coordinate * * @param value {Integer} The vertical position to scroll to. */ scrollToX : function(value) { // First flush queue before scroll qx.ui.core.queue.Manager.flush(); this.getChildControl("scrollbar-x").scrollTo(value); }, /** * Scrolls the element's content by the given left offset * * @param value {Integer} The vertical position to scroll to. */ scrollByX : function(value) { // First flush queue before scroll qx.ui.core.queue.Manager.flush(); this.getChildControl("scrollbar-x").scrollBy(value); }, /** * Returns the scroll left position of the content * * @return {Integer} Horizontal scroll position */ getScrollX : function() { var scrollbar = this.getChildControl("scrollbar-x", true); return scrollbar ? scrollbar.getPosition() : 0; }, /** * Scrolls the element's content to the given top coordinate * * @param value {Integer} The horizontal position to scroll to. */ scrollToY : function(value) { // First flush queue before scroll qx.ui.core.queue.Manager.flush(); this.getChildControl("scrollbar-y").scrollTo(value); }, /** * Scrolls the element's content by the given top offset * * @param value {Integer} The horizontal position to scroll to. * @return {void} */ scrollByY : function(value) { // First flush queue before scroll qx.ui.core.queue.Manager.flush(); this.getChildControl("scrollbar-y").scrollBy(value); }, /** * Returns the scroll top position of the content * * @return {Integer} Vertical scroll position */ getScrollY : function() { var scrollbar = this.getChildControl("scrollbar-y", true); return scrollbar ? scrollbar.getPosition() : 0; }, /* --------------------------------------------------------------------------- EVENT LISTENERS --------------------------------------------------------------------------- */ /** * Event handler for the scroll event of the horizontal scrollbar * * @param e {qx.event.type.Data} The scroll event object * @return {void} */ _onScrollBarX : function(e) { this.getChildControl("pane").scrollToX(e.getData()); }, /** * Event handler for the scroll event of the vertical scrollbar * * @param e {qx.event.type.Data} The scroll event object * @return {void} */ _onScrollBarY : function(e) { this.getChildControl("pane").scrollToY(e.getData()); }, /** * Event handler for the horizontal scroll event of the pane * * @param e {qx.event.type.Data} The scroll event object * @return {void} */ _onScrollPaneX : function(e) { this.scrollToX(e.getData()); }, /** * Event handler for the vertical scroll event of the pane * * @param e {qx.event.type.Data} The scroll event object * @return {void} */ _onScrollPaneY : function(e) { this.scrollToY(e.getData()); }, /** * Event handler for the touch move. * * @param e {qx.event.type.Touch} The touch event */ _onTouchMove : function(e) { this._onTouchMoveDirectional("x", e); this._onTouchMoveDirectional("y", e); // Stop bubbling and native event e.stop(); }, /** * Touch move handler for one direction. * * @param dir {String} Either 'x' or 'y' * @param e {qx.event.type.Touch} The touch event */ _onTouchMoveDirectional : function(dir, e) { var docDir = (dir == "x" ? "Left" : "Top"); // current scrollbar var scrollbar = this.getChildControl("scrollbar-" + dir, true); var show = this._isChildControlVisible("scrollbar-" + dir); if (show && scrollbar) { // get the delta for the current direction if(this.__old[dir] == 0) { var delta = 0; } else { var delta = -(e["getDocument" + docDir]() - this.__old[dir]); }; // save the old value for the current direction this.__old[dir] = e["getDocument" + docDir](); scrollbar.scrollBy(delta); // if we have an old timeout for the current direction, clear it if (this.__impulseTimerId[dir]) { clearTimeout(this.__impulseTimerId[dir]); this.__impulseTimerId[dir] = null; } // set up a new timer for the current direction this.__impulseTimerId[dir] = setTimeout(qx.lang.Function.bind(function(delta) { this.__handleScrollImpulse(delta, dir); }, this, delta), 100); } }, /** * Helper for momentum scrolling. * @param delta {Number} The delta from the last scrolling. * @param dir {String} Direction of the scrollbar ('x' or 'y'). */ __handleScrollImpulse : function(delta, dir) { // delete the old timer id this.__impulseTimerId[dir] = null; // do nothing if the scrollbar is not visible or we don't need to scroll var show = this._isChildControlVisible("scrollbar-" + dir); if (delta == 0 || !show) { return; } // linear momentum calculation if (delta > 0) { delta = Math.max(0, delta - 3); } else { delta = Math.min(0, delta + 3); } // set up a new timer with the new delta this.__impulseTimerId[dir] = setTimeout(qx.lang.Function.bind(function(delta, dir) { this.__handleScrollImpulse(delta, dir); }, this, delta, dir), 20); // scroll the desired new delta var scrollbar = this.getChildControl("scrollbar-" + dir, true); scrollbar.scrollBy(delta); }, /** * Event handler for visibility changes of horizontal scrollbar. * * @param e {qx.event.type.Event} Property change event * @return {void} */ _onChangeScrollbarXVisibility : function(e) { var showX = this._isChildControlVisible("scrollbar-x"); var showY = this._isChildControlVisible("scrollbar-y"); if (!showX) { this.scrollToX(0); } showX && showY ? this._showChildControl("corner") : this._excludeChildControl("corner"); }, /** * Event handler for visibility changes of horizontal scrollbar. * * @param e {qx.event.type.Event} Property change event * @return {void} */ _onChangeScrollbarYVisibility : function(e) { var showX = this._isChildControlVisible("scrollbar-x"); var showY = this._isChildControlVisible("scrollbar-y"); if (!showY) { this.scrollToY(0); } showX && showY ? this._showChildControl("corner") : this._excludeChildControl("corner"); }, /* --------------------------------------------------------------------------- HELPER METHODS --------------------------------------------------------------------------- */ /** * Computes the visibility state for scrollbars. * * @return {void} */ _computeScrollbars : function() { var pane = this.getChildControl("pane"); var content = pane.getChildren()[0]; if (!content) { this._excludeChildControl("scrollbar-x"); this._excludeChildControl("scrollbar-y"); return; } var innerSize = this.getInnerSize(); var paneSize = pane.getInnerSize(); var scrollSize = pane.getScrollSize(); // if the widget has not yet been rendered, return and try again in the // resize event if (!paneSize || !scrollSize) { return; } var scrollbarX = this.getScrollbarX(); var scrollbarY = this.getScrollbarY(); if (scrollbarX === "auto" && scrollbarY === "auto") { // Check if the container is big enough to show // the full content. var showX = scrollSize.width > innerSize.width; var showY = scrollSize.height > innerSize.height; // Dependency check // We need a special intelligence here when only one // of the autosized axis requires a scrollbar // This scrollbar may then influence the need // for the other one as well. if ((showX || showY) && !(showX && showY)) { if (showX) { showY = scrollSize.height > paneSize.height; } else if (showY) { showX = scrollSize.width > paneSize.width; } } } else { var showX = scrollbarX === "on"; var showY = scrollbarY === "on"; // Check auto values afterwards with already // corrected client dimensions if (scrollSize.width > (showX ? paneSize.width : innerSize.width) && scrollbarX === "auto") { showX = true; } if (scrollSize.height > (showX ? paneSize.height : innerSize.height) && scrollbarY === "auto") { showY = true; } } // Update scrollbars if (showX) { var barX = this.getChildControl("scrollbar-x"); barX.show(); barX.setMaximum(Math.max(0, scrollSize.width - paneSize.width)); barX.setKnobFactor((scrollSize.width === 0) ? 0 : paneSize.width / scrollSize.width); } else { this._excludeChildControl("scrollbar-x"); } if (showY) { var barY = this.getChildControl("scrollbar-y"); barY.show(); barY.setMaximum(Math.max(0, scrollSize.height - paneSize.height)); barY.setKnobFactor((scrollSize.height === 0) ? 0 : paneSize.height / scrollSize.height); } else { this._excludeChildControl("scrollbar-y"); } } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2011 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * This class is responsible for checking the scrolling behavior of the client. * * This class is used by {@link qx.core.Environment} and should not be used * directly. Please check its class comment for details how to use it. * * @internal */ qx.Bootstrap.define("qx.bom.client.Scroll", { statics : { /** * Check if the scrollbars should be positioned on top of the content. This * is true of OSX Lion when the scrollbars dissapear automatically. * * @internal * * @return {Boolean} <code>true</code> if the scrollbars should be * positioned on top of the content. */ scrollBarOverlayed : function() { var scrollBarWidth = qx.bom.element.Overflow.getScrollbarWidth(); var osx = qx.bom.client.OperatingSystem.getName() === "osx"; var nativeScrollBars = qx.core.Environment.get("qx.nativeScrollBars"); return scrollBarWidth == 0 && osx && nativeScrollBars; } }, defer : function(statics) { qx.core.Environment.add("os.scrollBarOverlayed", statics.scrollBarOverlayed); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * This class represents a scroll able pane. This means that this widget * may contain content which is bigger than the available (inner) * dimensions of this widget. The widget also offer methods to control * the scrolling position. It can only have exactly one child. */ qx.Class.define("qx.ui.core.scroll.ScrollPane", { extend : qx.ui.core.Widget, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ construct : function() { this.base(arguments); this.set({ minWidth: 0, minHeight: 0 }); // Automatically configure a "fixed" grow layout. this._setLayout(new qx.ui.layout.Grow()); // Add resize listener to "translate" event this.addListener("resize", this._onUpdate); var contentEl = this.getContentElement(); // Synchronizes the DOM scroll position with the properties contentEl.addListener("scroll", this._onScroll, this); // Fixed some browser quirks e.g. correcting scroll position // to the previous value on re-display of a pane contentEl.addListener("appear", this._onAppear, this); }, /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** Fired on resize of both the container or the content. */ update : "qx.event.type.Event" }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** The horizontal scroll position */ scrollX : { check : "qx.lang.Type.isNumber(value)&&value>=0&&value<=this.getScrollMaxX()", apply : "_applyScrollX", event : "scrollX", init : 0 }, /** The vertical scroll position */ scrollY : { check : "qx.lang.Type.isNumber(value)&&value>=0&&value<=this.getScrollMaxY()", apply : "_applyScrollY", event : "scrollY", init : 0 } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /* --------------------------------------------------------------------------- CONTENT MANAGEMENT --------------------------------------------------------------------------- */ /** * Configures the content of the scroll pane. Replaces any existing child * with the newly given one. * * @param widget {qx.ui.core.Widget?null} The content widget of the pane * @return {void} */ add : function(widget) { var old = this._getChildren()[0]; if (old) { this._remove(old); old.removeListener("resize", this._onUpdate, this); } if (widget) { this._add(widget); widget.addListener("resize", this._onUpdate, this); } }, /** * Removes the given widget from the content. The pane is empty * afterwards as only one child is supported by the pane. * * @param widget {qx.ui.core.Widget?null} The content widget of the pane * @return {void} */ remove : function(widget) { if (widget) { this._remove(widget); widget.removeListener("resize", this._onUpdate, this); } }, /** * Returns an array containing the current content. * * @return {Object[]} The content array */ getChildren : function() { return this._getChildren(); }, /* --------------------------------------------------------------------------- EVENT LISTENER --------------------------------------------------------------------------- */ /** * Event listener for resize event of content and container * * @param e {Event} Resize event object */ _onUpdate : function(e) { this.fireEvent("update"); }, /** * Event listener for scroll event of content * * @param e {qx.event.type.Event} Scroll event object */ _onScroll : function(e) { var contentEl = this.getContentElement(); this.setScrollX(contentEl.getScrollX()); this.setScrollY(contentEl.getScrollY()); }, /** * Event listener for appear event of content * * @param e {qx.event.type.Event} Appear event object */ _onAppear : function(e) { var contentEl = this.getContentElement(); var internalX = this.getScrollX(); var domX = contentEl.getScrollX(); if (internalX != domX) { contentEl.scrollToX(internalX); } var internalY = this.getScrollY(); var domY = contentEl.getScrollY(); if (internalY != domY) { contentEl.scrollToY(internalY); } }, /* --------------------------------------------------------------------------- ITEM LOCATION SUPPORT --------------------------------------------------------------------------- */ /** * Returns the top offset of the given item in relation to the * inner height of this widget. * * @param item {qx.ui.core.Widget} Item to query * @return {Integer} Top offset */ getItemTop : function(item) { var top = 0; do { top += item.getBounds().top; item = item.getLayoutParent(); } while (item && item !== this); return top; }, /** * Returns the top offset of the end of the given item in relation to the * inner height of this widget. * * @param item {qx.ui.core.Widget} Item to query * @return {Integer} Top offset */ getItemBottom : function(item) { return this.getItemTop(item) + item.getBounds().height; }, /** * Returns the left offset of the given item in relation to the * inner width of this widget. * * @param item {qx.ui.core.Widget} Item to query * @return {Integer} Top offset */ getItemLeft : function(item) { var left = 0; var parent; do { left += item.getBounds().left; parent = item.getLayoutParent(); if (parent) { left += parent.getInsets().left; } item = parent; } while (item && item !== this); return left; }, /** * Returns the left offset of the end of the given item in relation to the * inner width of this widget. * * @param item {qx.ui.core.Widget} Item to query * @return {Integer} Right offset */ getItemRight : function(item) { return this.getItemLeft(item) + item.getBounds().width; }, /* --------------------------------------------------------------------------- DIMENSIONS --------------------------------------------------------------------------- */ /** * The size (identical with the preferred size) of the content. * * @return {Map} Size of the content (keys: <code>width</code> and <code>height</code>) */ getScrollSize : function() { return this.getChildren()[0].getBounds(); }, /* --------------------------------------------------------------------------- SCROLL SUPPORT --------------------------------------------------------------------------- */ /** * The maximum horizontal scroll position. * * @return {Integer} Maximum horizontal scroll position. */ getScrollMaxX : function() { var paneSize = this.getInnerSize(); var scrollSize = this.getScrollSize(); if (paneSize && scrollSize) { return Math.max(0, scrollSize.width - paneSize.width); } return 0; }, /** * The maximum vertical scroll position. * * @return {Integer} Maximum vertical scroll position. */ getScrollMaxY : function() { var paneSize = this.getInnerSize(); var scrollSize = this.getScrollSize(); if (paneSize && scrollSize) { return Math.max(0, scrollSize.height - paneSize.height); } return 0; }, /** * Scrolls the element's content to the given left coordinate * * @param value {Integer} The vertical position to scroll to. * @return {void} */ scrollToX : function(value) { var max = this.getScrollMaxX(); if (value < 0) { value = 0; } else if (value > max) { value = max; } this.setScrollX(value); }, /** * Scrolls the element's content to the given top coordinate * * @param value {Integer} The horizontal position to scroll to. * @return {void} */ scrollToY : function(value) { var max = this.getScrollMaxY(); if (value < 0) { value = 0; } else if (value > max) { value = max; } this.setScrollY(value); }, /** * Scrolls the element's content horizontally by the given amount. * * @param x {Integer?0} Amount to scroll * @return {void} */ scrollByX : function(x) { this.scrollToX(this.getScrollX() + x); }, /** * Scrolls the element's content vertically by the given amount. * * @param y {Integer?0} Amount to scroll * @return {void} */ scrollByY : function(y) { this.scrollToY(this.getScrollY() + y); }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyScrollX : function(value) { this.getContentElement().scrollToX(value); }, // property apply _applyScrollY : function(value) { this.getContentElement().scrollToY(value); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) * Martin Wittemann (martinwittemann) * Christian Hagendorn (chris_schmidt) ************************************************************************ */ /** * A list of items. Displays an automatically scrolling list for all * added {@link qx.ui.form.ListItem} instances. Supports various * selection options: single, multi, ... */ qx.Class.define("qx.ui.form.List", { extend : qx.ui.core.scroll.AbstractScrollArea, implement : [ qx.ui.core.IMultiSelection, qx.ui.form.IForm, qx.ui.form.IModelSelection ], include : [ qx.ui.core.MRemoteChildrenHandling, qx.ui.core.MMultiSelectionHandling, qx.ui.form.MForm, qx.ui.form.MModelSelection ], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param horizontal {Boolean?false} Whether the list should be horizontal. */ construct : function(horizontal) { this.base(arguments); // Create content this.__content = this._createListItemContainer(); // Used to fire item add/remove events this.__content.addListener("addChildWidget", this._onAddChild, this); this.__content.addListener("removeChildWidget", this._onRemoveChild, this); // Add to scrollpane this.getChildControl("pane").add(this.__content); // Apply orientation if (horizontal) { this.setOrientation("horizontal"); } else { this.initOrientation(); } // Add keypress listener this.addListener("keypress", this._onKeyPress); this.addListener("keyinput", this._onKeyInput); // initialize the search string this.__pressedString = ""; }, /* ***************************************************************************** EVENTS ***************************************************************************** */ events : { /** * This event is fired after a list item was added to the list. The * {@link qx.event.type.Data#getData} method of the event returns the * added item. */ addItem : "qx.event.type.Data", /** * This event is fired after a list item has been removed from the list. * The {@link qx.event.type.Data#getData} method of the event returns the * removed item. */ removeItem : "qx.event.type.Data" }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { // overridden appearance : { refine : true, init : "list" }, // overridden focusable : { refine : true, init : true }, /** * Whether the list should be rendered horizontal or vertical. */ orientation : { check : ["horizontal", "vertical"], init : "vertical", apply : "_applyOrientation" }, /** Spacing between the items */ spacing : { check : "Integer", init : 0, apply : "_applySpacing", themeable : true }, /** Controls whether the inline-find feature is activated or not */ enableInlineFind : { check : "Boolean", init : true } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __pressedString : null, __lastKeyPress : null, /** {qx.ui.core.Widget} The children container */ __content : null, /** {Class} Pointer to the selection manager to use */ SELECTION_MANAGER : qx.ui.core.selection.ScrollArea, /* --------------------------------------------------------------------------- WIDGET API --------------------------------------------------------------------------- */ // overridden getChildrenContainer : function() { return this.__content; }, /** * Handle child widget adds on the content pane * * @param e {qx.event.type.Data} the event instance */ _onAddChild : function(e) { this.fireDataEvent("addItem", e.getData()); }, /** * Handle child widget removes on the content pane * * @param e {qx.event.type.Data} the event instance */ _onRemoveChild : function(e) { this.fireDataEvent("removeItem", e.getData()); }, /* --------------------------------------------------------------------------- PUBLIC API --------------------------------------------------------------------------- */ /** * Used to route external <code>keypress</code> events to the list * handling (in fact the manager of the list) * * @param e {qx.event.type.KeySequence} KeyPress event */ handleKeyPress : function(e) { if (!this._onKeyPress(e)) { this._getManager().handleKeyPress(e); } }, /* --------------------------------------------------------------------------- PROTECTED API --------------------------------------------------------------------------- */ /** * This container holds the list item widgets. * * @return {qx.ui.container.Composite} Container for the list item widgets */ _createListItemContainer : function() { return new qx.ui.container.Composite; }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyOrientation : function(value, old) { // Create new layout var horizontal = value === "horizontal"; var layout = horizontal ? new qx.ui.layout.HBox() : new qx.ui.layout.VBox(); // Configure content var content = this.__content; content.setLayout(layout); content.setAllowGrowX(!horizontal); content.setAllowGrowY(horizontal); // Configure spacing this._applySpacing(this.getSpacing()); }, // property apply _applySpacing : function(value, old) { this.__content.getLayout().setSpacing(value); }, /* --------------------------------------------------------------------------- EVENT HANDLER --------------------------------------------------------------------------- */ /** * Event listener for <code>keypress</code> events. * * @param e {qx.event.type.KeySequence} KeyPress event * @return {Boolean} Whether the event was processed */ _onKeyPress : function(e) { // Execute action on press <ENTER> if (e.getKeyIdentifier() == "Enter" && !e.isAltPressed()) { var items = this.getSelection(); for (var i=0; i<items.length; i++) { items[i].fireEvent("action"); } return true; } return false; }, /* --------------------------------------------------------------------------- FIND SUPPORT --------------------------------------------------------------------------- */ /** * Handles the inline find - if enabled * * @param e {qx.event.type.KeyInput} key input event */ _onKeyInput : function(e) { // do nothing if the find is disabled if (!this.getEnableInlineFind()) { return; } // Only useful in single or one selection mode var mode = this.getSelectionMode(); if (!(mode === "single" || mode === "one")) { return; } // Reset string after a second of non pressed key if (((new Date).valueOf() - this.__lastKeyPress) > 1000) { this.__pressedString = ""; } // Combine keys the user pressed to a string this.__pressedString += e.getChar(); // Find matching item var matchedItem = this.findItemByLabelFuzzy(this.__pressedString); // if an item was found, select it if (matchedItem) { this.setSelection([matchedItem]); } // Store timestamp this.__lastKeyPress = (new Date).valueOf(); }, /** * Takes the given string and tries to find a ListItem * which starts with this string. The search is not case sensitive and the * first found ListItem will be returned. If there could not be found any * qualifying list item, null will be returned. * * @param search {String} The text with which the label of the ListItem should start with * @return {qx.ui.form.ListItem} The found ListItem or null */ findItemByLabelFuzzy : function(search) { // lower case search text search = search.toLowerCase(); // get all items of the list var items = this.getChildren(); // go threw all items for (var i=0, l=items.length; i<l; i++) { // get the label of the current item var currentLabel = items[i].getLabel(); // if the label fits with the search text (ignore case, begins with) if (currentLabel && currentLabel.toLowerCase().indexOf(search) == 0) { // just return the first found element return items[i]; } } // if no element was found, return null return null; }, /** * Find an item by its {@link qx.ui.basic.Atom#getLabel}. * * @param search {String} A label or any item * @param ignoreCase {Boolean?true} description * @return {qx.ui.form.ListItem} The found ListItem or null */ findItem : function(search, ignoreCase) { // lowercase search if (ignoreCase !== false) { search = search.toLowerCase(); }; // get all items of the list var items = this.getChildren(); var item; // go through all items for (var i=0, l=items.length; i<l; i++) { item = items[i]; // get the content of the label; text content when rich var label; if (item.isRich()) { var control = item.getChildControl("label", true); if (control) { var labelNode = control.getContentElement().getDomElement(); if (labelNode) { label = qx.bom.element.Attribute.get(labelNode, "text"); } } } else { label = item.getLabel(); } if (label != null) { if (label.translate) { label = label.translate(); } if (ignoreCase !== false) { label = label.toLowerCase(); } if (label.toString() == search.toString()) { return item; } } } return null; } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this._disposeObjects("__content"); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) * Sebastian Werner (wpbasti) * Jonathan Weiß (jonathan_rass) ************************************************************************ */ /** * Basic class for a selectbox like lists. Basically supports a popup * with a list and the whole children management. * * @childControl list {qx.ui.form.List} list component of the selectbox * @childControl popup {qx.ui.popup.Popup} popup which shows the list * */ qx.Class.define("qx.ui.form.AbstractSelectBox", { extend : qx.ui.core.Widget, include : [ qx.ui.core.MRemoteChildrenHandling, qx.ui.form.MForm ], implement : [ qx.ui.form.IForm ], type : "abstract", /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ construct : function() { this.base(arguments); // set the layout var layout = new qx.ui.layout.HBox(); this._setLayout(layout); layout.setAlignY("middle"); // Register listeners this.addListener("keypress", this._onKeyPress); this.addListener("blur", this._onBlur, this); // register mouse wheel listener var root = qx.core.Init.getApplication().getRoot(); root.addListener("mousewheel", this._onMousewheel, this, true); // register the resize listener this.addListener("resize", this._onResize, this); }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { // overridden focusable : { refine : true, init : true }, // overridden width : { refine : true, init : 120 }, /** * The maximum height of the list popup. Setting this value to * <code>null</code> will set cause the list to be auto-sized. */ maxListHeight : { check : "Number", apply : "_applyMaxListHeight", nullable: true, init : 200 }, /** * Formatter which format the value from the selected <code>ListItem</code>. * Uses the default formatter {@link #_defaultFormat}. */ format : { check : "Function", init : function(item) { return this._defaultFormat(item); }, nullable : true } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { // overridden _createChildControlImpl : function(id, hash) { var control; switch(id) { case "list": control = new qx.ui.form.List().set({ focusable: false, keepFocus: true, height: null, width: null, maxHeight: this.getMaxListHeight(), selectionMode: "one", quickSelection: true }); control.addListener("changeSelection", this._onListChangeSelection, this); control.addListener("mousedown", this._onListMouseDown, this); break; case "popup": control = new qx.ui.popup.Popup(new qx.ui.layout.VBox); control.setAutoHide(false); control.setKeepActive(true); control.addListener("mouseup", this.close, this); control.add(this.getChildControl("list")); control.addListener("changeVisibility", this._onPopupChangeVisibility, this); break; } return control || this.base(arguments, id); }, /* --------------------------------------------------------------------------- APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyMaxListHeight : function(value, old) { this.getChildControl("list").setMaxHeight(value); }, /* --------------------------------------------------------------------------- PUBLIC METHODS --------------------------------------------------------------------------- */ /** * Returns the list widget. * @return {qx.ui.form.List} the list */ getChildrenContainer : function() { return this.getChildControl("list"); }, /* --------------------------------------------------------------------------- LIST STUFF --------------------------------------------------------------------------- */ /** * Shows the list popup. */ open : function() { var popup = this.getChildControl("popup"); popup.placeToWidget(this, true); popup.show(); }, /** * Hides the list popup. */ close : function() { this.getChildControl("popup").hide(); }, /** * Toggles the popup's visibility. */ toggle : function() { var isListOpen = this.getChildControl("popup").isVisible(); if (isListOpen) { this.close(); } else { this.open(); } }, /* --------------------------------------------------------------------------- FORMAT HANDLING --------------------------------------------------------------------------- */ /** * Return the formatted label text from the <code>ListItem</code>. * The formatter removes all HTML tags and converts all HTML entities * to string characters when the rich property is <code>true</code>. * * @param item {ListItem} The list item to format. * @return {String} The formatted text. */ _defaultFormat : function(item) { var valueLabel = item ? item.getLabel() : ""; var rich = item ? item.getRich() : false; if (rich) { valueLabel = valueLabel.replace(/<[^>]+?>/g, ""); valueLabel = qx.bom.String.unescape(valueLabel); } return valueLabel; }, /* --------------------------------------------------------------------------- EVENT LISTENERS --------------------------------------------------------------------------- */ /** * Handler for the blur event of the current widget. * * @param e {qx.event.type.Focus} The blur event. */ _onBlur : function(e) { this.close(); }, /** * Reacts on special keys and forwards other key events to the list widget. * * @param e {qx.event.type.KeySequence} Keypress event */ _onKeyPress : function(e) { // get the key identifier var identifier = e.getKeyIdentifier(); var listPopup = this.getChildControl("popup"); // disabled pageUp and pageDown keys if (listPopup.isHidden() && (identifier == "PageDown" || identifier == "PageUp")) { e.stopPropagation(); } // hide the list always on escape else if (!listPopup.isHidden() && identifier == "Escape") { this.close(); e.stop(); } // forward the rest of the events to the list else { this.getChildControl("list").handleKeyPress(e); } }, /** * Close the pop-up if the mousewheel event isn't on the pup-up window. * * @param e {qx.event.type.Mouse} Mousewheel event. */ _onMousewheel : function(e) { var target = e.getTarget(); var popup = this.getChildControl("popup", true); if (popup == null) { return; } if (qx.ui.core.Widget.contains(popup, target)) { // needed for ComboBox widget inside an inline application e.preventDefault(); } else { this.close(); } }, /** * Updates list minimum size. * * @param e {qx.event.type.Data} Data event */ _onResize : function(e){ this.getChildControl("popup").setMinWidth(e.getData().width); }, /** * Syncs the own property from the list change * * @param e {qx.event.type.Data} Data Event */ _onListChangeSelection : function(e) { throw new Error("Abstract method: _onListChangeSelection()"); }, /** * Redirects mousedown event from the list to this widget. * * @param e {qx.event.type.Mouse} Mouse Event */ _onListMouseDown : function(e) { throw new Error("Abstract method: _onListMouseDown()"); }, /** * Redirects changeVisibility event from the list to this widget. * * @param e {qx.event.type.Data} Property change event */ _onPopupChangeVisibility : function(e) { e.getData() == "visible" ? this.addState("popupOpen") : this.removeState("popupOpen"); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { var root = qx.core.Init.getApplication().getRoot(); if (root) { root.removeListener("mousewheel", this._onMousewheel, this, true); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A Collection of utility functions to escape and unescape strings. */ qx.Class.define("qx.bom.String", { /* ***************************************************************************** STATICS ***************************************************************************** */ statics : { /** Mapping of HTML entity names to the corresponding char code */ TO_CHARCODE : { "quot" : 34, // " - double-quote "amp" : 38, // & "lt" : 60, // < "gt" : 62, // > // http://www.w3.org/TR/REC-html40/sgml/entities.html // ISO 8859-1 characters "nbsp" : 160, // no-break space "iexcl" : 161, // inverted exclamation mark "cent" : 162, // cent sign "pound" : 163, // pound sterling sign "curren" : 164, // general currency sign "yen" : 165, // yen sign "brvbar" : 166, // broken (vertical) bar "sect" : 167, // section sign "uml" : 168, // umlaut (dieresis) "copy" : 169, // copyright sign "ordf" : 170, // ordinal indicator, feminine "laquo" : 171, // angle quotation mark, left "not" : 172, // not sign "shy" : 173, // soft hyphen "reg" : 174, // registered sign "macr" : 175, // macron "deg" : 176, // degree sign "plusmn" : 177, // plus-or-minus sign "sup2" : 178, // superscript two "sup3" : 179, // superscript three "acute" : 180, // acute accent "micro" : 181, // micro sign "para" : 182, // pilcrow (paragraph sign) "middot" : 183, // middle dot "cedil" : 184, // cedilla "sup1" : 185, // superscript one "ordm" : 186, // ordinal indicator, masculine "raquo" : 187, // angle quotation mark, right "frac14" : 188, // fraction one-quarter "frac12" : 189, // fraction one-half "frac34" : 190, // fraction three-quarters "iquest" : 191, // inverted question mark "Agrave" : 192, // capital A, grave accent "Aacute" : 193, // capital A, acute accent "Acirc" : 194, // capital A, circumflex accent "Atilde" : 195, // capital A, tilde "Auml" : 196, // capital A, dieresis or umlaut mark "Aring" : 197, // capital A, ring "AElig" : 198, // capital AE diphthong (ligature) "Ccedil" : 199, // capital C, cedilla "Egrave" : 200, // capital E, grave accent "Eacute" : 201, // capital E, acute accent "Ecirc" : 202, // capital E, circumflex accent "Euml" : 203, // capital E, dieresis or umlaut mark "Igrave" : 204, // capital I, grave accent "Iacute" : 205, // capital I, acute accent "Icirc" : 206, // capital I, circumflex accent "Iuml" : 207, // capital I, dieresis or umlaut mark "ETH" : 208, // capital Eth, Icelandic "Ntilde" : 209, // capital N, tilde "Ograve" : 210, // capital O, grave accent "Oacute" : 211, // capital O, acute accent "Ocirc" : 212, // capital O, circumflex accent "Otilde" : 213, // capital O, tilde "Ouml" : 214, // capital O, dieresis or umlaut mark "times" : 215, // multiply sign "Oslash" : 216, // capital O, slash "Ugrave" : 217, // capital U, grave accent "Uacute" : 218, // capital U, acute accent "Ucirc" : 219, // capital U, circumflex accent "Uuml" : 220, // capital U, dieresis or umlaut mark "Yacute" : 221, // capital Y, acute accent "THORN" : 222, // capital THORN, Icelandic "szlig" : 223, // small sharp s, German (sz ligature) "agrave" : 224, // small a, grave accent "aacute" : 225, // small a, acute accent "acirc" : 226, // small a, circumflex accent "atilde" : 227, // small a, tilde "auml" : 228, // small a, dieresis or umlaut mark "aring" : 229, // small a, ring "aelig" : 230, // small ae diphthong (ligature) "ccedil" : 231, // small c, cedilla "egrave" : 232, // small e, grave accent "eacute" : 233, // small e, acute accent "ecirc" : 234, // small e, circumflex accent "euml" : 235, // small e, dieresis or umlaut mark "igrave" : 236, // small i, grave accent "iacute" : 237, // small i, acute accent "icirc" : 238, // small i, circumflex accent "iuml" : 239, // small i, dieresis or umlaut mark "eth" : 240, // small eth, Icelandic "ntilde" : 241, // small n, tilde "ograve" : 242, // small o, grave accent "oacute" : 243, // small o, acute accent "ocirc" : 244, // small o, circumflex accent "otilde" : 245, // small o, tilde "ouml" : 246, // small o, dieresis or umlaut mark "divide" : 247, // divide sign "oslash" : 248, // small o, slash "ugrave" : 249, // small u, grave accent "uacute" : 250, // small u, acute accent "ucirc" : 251, // small u, circumflex accent "uuml" : 252, // small u, dieresis or umlaut mark "yacute" : 253, // small y, acute accent "thorn" : 254, // small thorn, Icelandic "yuml" : 255, // small y, dieresis or umlaut mark // Latin Extended-B "fnof" : 402, // latin small f with hook = function= florin, U+0192 ISOtech // Greek "Alpha" : 913, // greek capital letter alpha, U+0391 "Beta" : 914, // greek capital letter beta, U+0392 "Gamma" : 915, // greek capital letter gamma,U+0393 ISOgrk3 "Delta" : 916, // greek capital letter delta,U+0394 ISOgrk3 "Epsilon" : 917, // greek capital letter epsilon, U+0395 "Zeta" : 918, // greek capital letter zeta, U+0396 "Eta" : 919, // greek capital letter eta, U+0397 "Theta" : 920, // greek capital letter theta,U+0398 ISOgrk3 "Iota" : 921, // greek capital letter iota, U+0399 "Kappa" : 922, // greek capital letter kappa, U+039A "Lambda" : 923, // greek capital letter lambda,U+039B ISOgrk3 "Mu" : 924, // greek capital letter mu, U+039C "Nu" : 925, // greek capital letter nu, U+039D "Xi" : 926, // greek capital letter xi, U+039E ISOgrk3 "Omicron" : 927, // greek capital letter omicron, U+039F "Pi" : 928, // greek capital letter pi, U+03A0 ISOgrk3 "Rho" : 929, // greek capital letter rho, U+03A1 // there is no Sigmaf, and no U+03A2 character either "Sigma" : 931, // greek capital letter sigma,U+03A3 ISOgrk3 "Tau" : 932, // greek capital letter tau, U+03A4 "Upsilon" : 933, // greek capital letter upsilon,U+03A5 ISOgrk3 "Phi" : 934, // greek capital letter phi,U+03A6 ISOgrk3 "Chi" : 935, // greek capital letter chi, U+03A7 "Psi" : 936, // greek capital letter psi,U+03A8 ISOgrk3 "Omega" : 937, // greek capital letter omega,U+03A9 ISOgrk3 "alpha" : 945, // greek small letter alpha,U+03B1 ISOgrk3 "beta" : 946, // greek small letter beta, U+03B2 ISOgrk3 "gamma" : 947, // greek small letter gamma,U+03B3 ISOgrk3 "delta" : 948, // greek small letter delta,U+03B4 ISOgrk3 "epsilon" : 949, // greek small letter epsilon,U+03B5 ISOgrk3 "zeta" : 950, // greek small letter zeta, U+03B6 ISOgrk3 "eta" : 951, // greek small letter eta, U+03B7 ISOgrk3 "theta" : 952, // greek small letter theta,U+03B8 ISOgrk3 "iota" : 953, // greek small letter iota, U+03B9 ISOgrk3 "kappa" : 954, // greek small letter kappa,U+03BA ISOgrk3 "lambda" : 955, // greek small letter lambda,U+03BB ISOgrk3 "mu" : 956, // greek small letter mu, U+03BC ISOgrk3 "nu" : 957, // greek small letter nu, U+03BD ISOgrk3 "xi" : 958, // greek small letter xi, U+03BE ISOgrk3 "omicron" : 959, // greek small letter omicron, U+03BF NEW "pi" : 960, // greek small letter pi, U+03C0 ISOgrk3 "rho" : 961, // greek small letter rho, U+03C1 ISOgrk3 "sigmaf" : 962, // greek small letter final sigma,U+03C2 ISOgrk3 "sigma" : 963, // greek small letter sigma,U+03C3 ISOgrk3 "tau" : 964, // greek small letter tau, U+03C4 ISOgrk3 "upsilon" : 965, // greek small letter upsilon,U+03C5 ISOgrk3 "phi" : 966, // greek small letter phi, U+03C6 ISOgrk3 "chi" : 967, // greek small letter chi, U+03C7 ISOgrk3 "psi" : 968, // greek small letter psi, U+03C8 ISOgrk3 "omega" : 969, // greek small letter omega,U+03C9 ISOgrk3 "thetasym" : 977, // greek small letter theta symbol,U+03D1 NEW "upsih" : 978, // greek upsilon with hook symbol,U+03D2 NEW "piv" : 982, // greek pi symbol, U+03D6 ISOgrk3 // General Punctuation "bull" : 8226, // bullet = black small circle,U+2022 ISOpub // bullet is NOT the same as bullet operator, U+2219 "hellip" : 8230, // horizontal ellipsis = three dot leader,U+2026 ISOpub "prime" : 8242, // prime = minutes = feet, U+2032 ISOtech "Prime" : 8243, // double prime = seconds = inches,U+2033 ISOtech "oline" : 8254, // overline = spacing overscore,U+203E NEW "frasl" : 8260, // fraction slash, U+2044 NEW // Letterlike Symbols "weierp" : 8472, // script capital P = power set= Weierstrass p, U+2118 ISOamso "image" : 8465, // blackletter capital I = imaginary part,U+2111 ISOamso "real" : 8476, // blackletter capital R = real part symbol,U+211C ISOamso "trade" : 8482, // trade mark sign, U+2122 ISOnum "alefsym" : 8501, // alef symbol = first transfinite cardinal,U+2135 NEW // alef symbol is NOT the same as hebrew letter alef,U+05D0 although the same glyph could be used to depict both characters // Arrows "larr" : 8592, // leftwards arrow, U+2190 ISOnum "uarr" : 8593, // upwards arrow, U+2191 ISOnum--> "rarr" : 8594, // rightwards arrow, U+2192 ISOnum "darr" : 8595, // downwards arrow, U+2193 ISOnum "harr" : 8596, // left right arrow, U+2194 ISOamsa "crarr" : 8629, // downwards arrow with corner leftwards= carriage return, U+21B5 NEW "lArr" : 8656, // leftwards double arrow, U+21D0 ISOtech // ISO 10646 does not say that lArr is the same as the 'is implied by' arrowbut also does not have any other character for that function. So ? lArr canbe used for 'is implied by' as ISOtech suggests "uArr" : 8657, // upwards double arrow, U+21D1 ISOamsa "rArr" : 8658, // rightwards double arrow,U+21D2 ISOtech // ISO 10646 does not say this is the 'implies' character but does not have another character with this function so ?rArr can be used for 'implies' as ISOtech suggests "dArr" : 8659, // downwards double arrow, U+21D3 ISOamsa "hArr" : 8660, // left right double arrow,U+21D4 ISOamsa // Mathematical Operators "forall" : 8704, // for all, U+2200 ISOtech "part" : 8706, // partial differential, U+2202 ISOtech "exist" : 8707, // there exists, U+2203 ISOtech "empty" : 8709, // empty set = null set = diameter,U+2205 ISOamso "nabla" : 8711, // nabla = backward difference,U+2207 ISOtech "isin" : 8712, // element of, U+2208 ISOtech "notin" : 8713, // not an element of, U+2209 ISOtech "ni" : 8715, // contains as member, U+220B ISOtech // should there be a more memorable name than 'ni'? "prod" : 8719, // n-ary product = product sign,U+220F ISOamsb // prod is NOT the same character as U+03A0 'greek capital letter pi' though the same glyph might be used for both "sum" : 8721, // n-ary summation, U+2211 ISOamsb // sum is NOT the same character as U+03A3 'greek capital letter sigma' though the same glyph might be used for both "minus" : 8722, // minus sign, U+2212 ISOtech "lowast" : 8727, // asterisk operator, U+2217 ISOtech "radic" : 8730, // square root = radical sign,U+221A ISOtech "prop" : 8733, // proportional to, U+221D ISOtech "infin" : 8734, // infinity, U+221E ISOtech "ang" : 8736, // angle, U+2220 ISOamso "and" : 8743, // logical and = wedge, U+2227 ISOtech "or" : 8744, // logical or = vee, U+2228 ISOtech "cap" : 8745, // intersection = cap, U+2229 ISOtech "cup" : 8746, // union = cup, U+222A ISOtech "int" : 8747, // integral, U+222B ISOtech "there4" : 8756, // therefore, U+2234 ISOtech "sim" : 8764, // tilde operator = varies with = similar to,U+223C ISOtech // tilde operator is NOT the same character as the tilde, U+007E,although the same glyph might be used to represent both "cong" : 8773, // approximately equal to, U+2245 ISOtech "asymp" : 8776, // almost equal to = asymptotic to,U+2248 ISOamsr "ne" : 8800, // not equal to, U+2260 ISOtech "equiv" : 8801, // identical to, U+2261 ISOtech "le" : 8804, // less-than or equal to, U+2264 ISOtech "ge" : 8805, // greater-than or equal to,U+2265 ISOtech "sub" : 8834, // subset of, U+2282 ISOtech "sup" : 8835, // superset of, U+2283 ISOtech // note that nsup, 'not a superset of, U+2283' is not covered by the Symbol font encoding and is not included. Should it be, for symmetry?It is in ISOamsn --> <!ENTITY nsub": 8836, //not a subset of, U+2284 ISOamsn "sube" : 8838, // subset of or equal to, U+2286 ISOtech "supe" : 8839, // superset of or equal to,U+2287 ISOtech "oplus" : 8853, // circled plus = direct sum,U+2295 ISOamsb "otimes" : 8855, // circled times = vector product,U+2297 ISOamsb "perp" : 8869, // up tack = orthogonal to = perpendicular,U+22A5 ISOtech "sdot" : 8901, // dot operator, U+22C5 ISOamsb // dot operator is NOT the same character as U+00B7 middle dot // Miscellaneous Technical "lceil" : 8968, // left ceiling = apl upstile,U+2308 ISOamsc "rceil" : 8969, // right ceiling, U+2309 ISOamsc "lfloor" : 8970, // left floor = apl downstile,U+230A ISOamsc "rfloor" : 8971, // right floor, U+230B ISOamsc "lang" : 9001, // left-pointing angle bracket = bra,U+2329 ISOtech // lang is NOT the same character as U+003C 'less than' or U+2039 'single left-pointing angle quotation mark' "rang" : 9002, // right-pointing angle bracket = ket,U+232A ISOtech // rang is NOT the same character as U+003E 'greater than' or U+203A 'single right-pointing angle quotation mark' // Geometric Shapes "loz" : 9674, // lozenge, U+25CA ISOpub // Miscellaneous Symbols "spades" : 9824, // black spade suit, U+2660 ISOpub // black here seems to mean filled as opposed to hollow "clubs" : 9827, // black club suit = shamrock,U+2663 ISOpub "hearts" : 9829, // black heart suit = valentine,U+2665 ISOpub "diams" : 9830, // black diamond suit, U+2666 ISOpub // Latin Extended-A "OElig" : 338, // -- latin capital ligature OE,U+0152 ISOlat2 "oelig" : 339, // -- latin small ligature oe, U+0153 ISOlat2 // ligature is a misnomer, this is a separate character in some languages "Scaron" : 352, // -- latin capital letter S with caron,U+0160 ISOlat2 "scaron" : 353, // -- latin small letter s with caron,U+0161 ISOlat2 "Yuml" : 376, // -- latin capital letter Y with diaeresis,U+0178 ISOlat2 // Spacing Modifier Letters "circ" : 710, // -- modifier letter circumflex accent,U+02C6 ISOpub "tilde" : 732, // small tilde, U+02DC ISOdia // General Punctuation "ensp" : 8194, // en space, U+2002 ISOpub "emsp" : 8195, // em space, U+2003 ISOpub "thinsp" : 8201, // thin space, U+2009 ISOpub "zwnj" : 8204, // zero width non-joiner,U+200C NEW RFC 2070 "zwj" : 8205, // zero width joiner, U+200D NEW RFC 2070 "lrm" : 8206, // left-to-right mark, U+200E NEW RFC 2070 "rlm" : 8207, // right-to-left mark, U+200F NEW RFC 2070 "ndash" : 8211, // en dash, U+2013 ISOpub "mdash" : 8212, // em dash, U+2014 ISOpub "lsquo" : 8216, // left single quotation mark,U+2018 ISOnum "rsquo" : 8217, // right single quotation mark,U+2019 ISOnum "sbquo" : 8218, // single low-9 quotation mark, U+201A NEW "ldquo" : 8220, // left double quotation mark,U+201C ISOnum "rdquo" : 8221, // right double quotation mark,U+201D ISOnum "bdquo" : 8222, // double low-9 quotation mark, U+201E NEW "dagger" : 8224, // dagger, U+2020 ISOpub "Dagger" : 8225, // double dagger, U+2021 ISOpub "permil" : 8240, // per mille sign, U+2030 ISOtech "lsaquo" : 8249, // single left-pointing angle quotation mark,U+2039 ISO proposed // lsaquo is proposed but not yet ISO standardized "rsaquo" : 8250, // single right-pointing angle quotation mark,U+203A ISO proposed // rsaquo is proposed but not yet ISO standardized "euro" : 8364 // -- euro sign, U+20AC NEW }, /** * Escapes the characters in a <code>String</code> using HTML entities. * * For example: <tt>"bread" & "butter"</tt> => <tt>&amp;quot;bread&amp;quot; &amp;amp; &amp;quot;butter&amp;quot;</tt>. * Supports all known HTML 4.0 entities, including funky accents. * * * <a href="http://www.w3.org/TR/REC-html32#latin1">HTML 3.2 Character Entities for ISO Latin-1</a> * * <a href="http://www.w3.org/TR/REC-html40/sgml/entities.html">HTML 4.0 Character entity references</a> * * <a href="http://www.w3.org/TR/html401/charset.html#h-5.3">HTML 4.01 Character References</a> * * <a href="http://www.w3.org/TR/html401/charset.html#code-position">HTML 4.01 Code positions</a> * * @param str {String} the String to escape * @return {String} a new escaped String * @see #unescape */ escape : function(str) { return qx.util.StringEscape.escape(str, qx.bom.String.FROM_CHARCODE); }, /** * Unescapes a string containing entity escapes to a string * containing the actual Unicode characters corresponding to the * escapes. Supports HTML 4.0 entities. * * For example, the string "&amp;lt;Fran&amp;ccedil;ais&amp;gt;" * will become "&lt;Fran&ccedil;ais&gt;" * * If an entity is unrecognized, it is left alone, and inserted * verbatim into the result string. e.g. "&amp;gt;&amp;zzzz;x" will * become "&gt;&amp;zzzz;x". * * @param str {String} the String to unescape, may be null * @return {var} a new unescaped String * @see #escape */ unescape : function(str) { return qx.util.StringEscape.unescape(str, qx.bom.String.TO_CHARCODE); }, /** * Converts a plain text string into HTML. * This is similar to {@link #escape} but converts new lines to * <tt>&lt:br&gt:</tt> and preserves whitespaces. * * @param str {String} the String to convert * @return {String} a new converted String * @see #escape */ fromText : function(str) { return qx.bom.String.escape(str).replace(/( |\n)/g, function(chr) { var map = { " " : " &nbsp;", "\n" : "<br>" }; return map[chr] || chr; }); }, /** * Converts HTML to plain text. * * * Strips all HTML tags * * converts <tt>&lt:br&gt:</tt> to new line * * unescapes HTML entities * * @param str {String} HTML string to converts * @return {String} plain text representation of the HTML string */ toText : function(str) { return qx.bom.String.unescape(str.replace(/\s+|<([^>])+>/gi, function(chr) //return qx.bom.String.unescape(str.replace(/<\/?[^>]+(>|$)/gi, function(chr) { if (chr.indexOf("<br") === 0) { return "\n"; } else if (chr.length > 0 && chr.replace(/^\s*/, "").replace(/\s*$/, "") == "") { return " "; } else { return ""; } })); } }, /* ***************************************************************************** DEFER ***************************************************************************** */ defer : function(statics) { /** Mapping of char codes to HTML entity names */ statics.FROM_CHARCODE = qx.lang.Object.invert(statics.TO_CHARCODE) } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * Generic escaping and unescaping of DOM strings. * * {@link qx.bom.String} for (un)escaping of HTML strings. * {@link qx.xml.String} for (un)escaping of XML strings. */ qx.Class.define("qx.util.StringEscape", { statics : { /** * generic escaping method * * @param str {String} string to escape * @param charCodeToEntities {Map} entity to charcode map * @return {String} escaped string * @signature function(str, charCodeToEntities) */ escape : function(str, charCodeToEntities) { var entity, result = ""; for (var i=0, l=str.length; i<l; i++) { var chr = str.charAt(i); var code = chr.charCodeAt(0); if (charCodeToEntities[code]) { entity = "&" + charCodeToEntities[code] + ";"; } else { if (code > 0x7F) { entity = "&#" + code + ";"; } else { entity = chr; } } result += entity; } return result; }, /** * generic unescaping method * * @param str {String} string to unescape * @param entitiesToCharCode {Map} charcode to entity map * @return {String} unescaped string */ unescape : function(str, entitiesToCharCode) { return str.replace(/&[#\w]+;/gi, function(entity) { var chr = entity; var entity = entity.substring(1, entity.length - 1); var code = entitiesToCharCode[entity]; if (code) { chr = String.fromCharCode(code); } else { if (entity.charAt(0) == '#') { if (entity.charAt(1).toUpperCase() == 'X') { code = entity.substring(2); // match hex number if (code.match(/^[0-9A-Fa-f]+$/gi)) { chr = String.fromCharCode(parseInt(code, 16)); } } else { code = entity.substring(1); // match integer if (code.match(/^\d+$/gi)) { chr = String.fromCharCode(parseInt(code, 10)); } } } } return chr; }); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) * Sebastian Werner (wpbasti) * Jonathan Weiß (jonathan_rass) * Christian Hagendorn (chris_schmidt) ************************************************************************ */ /** * A form widget which allows a single selection. Looks somewhat like * a normal button, but opens a list of items to select when clicking on it. * * Keep in mind that the SelectBox widget has always a selected item (due to the * single selection mode). Right after adding the first item a <code>changeSelection</code> * event is fired. * * <pre class='javascript'> * var selectBox = new qx.ui.form.SelectBox(); * * selectBox.addListener("changeSelection", function(e) { * // ... * }); * * // now the 'changeSelection' event is fired * selectBox.add(new qx.ui.form.ListItem("Item 1"); * </pre> * * @childControl spacer {qx.ui.core.Spacer} flexible spacer widget * @childControl atom {qx.ui.basic.Atom} shows the text and icon of the content * @childControl arrow {qx.ui.basic.Image} shows the arrow to open the popup */ qx.Class.define("qx.ui.form.SelectBox", { extend : qx.ui.form.AbstractSelectBox, implement : [ qx.ui.core.ISingleSelection, qx.ui.form.IModelSelection ], include : [qx.ui.core.MSingleSelectionHandling, qx.ui.form.MModelSelection], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ construct : function() { this.base(arguments); this._createChildControl("atom"); this._createChildControl("spacer"); this._createChildControl("arrow"); // Register listener this.addListener("mouseover", this._onMouseOver, this); this.addListener("mouseout", this._onMouseOut, this); this.addListener("click", this._onClick, this); this.addListener("mousewheel", this._onMouseWheel, this); this.addListener("keyinput", this._onKeyInput, this); this.addListener("changeSelection", this.__onChangeSelection, this); }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { // overridden appearance : { refine : true, init : "selectbox" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** {qx.ui.form.ListItem} instance */ __preSelectedItem : null, /* --------------------------------------------------------------------------- WIDGET API --------------------------------------------------------------------------- */ // overridden _createChildControlImpl : function(id, hash) { var control; switch(id) { case "spacer": control = new qx.ui.core.Spacer(); this._add(control, {flex: 1}); break; case "atom": control = new qx.ui.basic.Atom(" "); control.setCenter(false); control.setAnonymous(true); this._add(control, {flex:1}); break; case "arrow": control = new qx.ui.basic.Image(); control.setAnonymous(true); this._add(control); break; } return control || this.base(arguments, id); }, // overridden /** * @lint ignoreReferenceField(_forwardStates) */ _forwardStates : { focused : true }, /* --------------------------------------------------------------------------- HELPER METHODS FOR SELECTION API --------------------------------------------------------------------------- */ /** * Returns the list items for the selection. * * @return {qx.ui.form.ListItem[]} List itmes to select. */ _getItems : function() { return this.getChildrenContainer().getChildren(); }, /** * Returns if the selection could be empty or not. * * @return {Boolean} <code>true</code> If selection could be empty, * <code>false</code> otherwise. */ _isAllowEmptySelection: function() { return this.getChildrenContainer().getSelectionMode() !== "one"; }, /** * Event handler for <code>changeSelection</code>. * * @param e {qx.event.type.Data} Data event. */ __onChangeSelection : function(e) { var listItem = e.getData()[0]; var list = this.getChildControl("list"); if (list.getSelection()[0] != listItem) { if(listItem) { list.setSelection([listItem]); } else { list.resetSelection(); } } this.__updateIcon(); this.__updateLabel(); }, /** * Sets the icon inside the list to match the selected ListItem. */ __updateIcon : function() { var listItem = this.getChildControl("list").getSelection()[0]; var atom = this.getChildControl("atom"); var icon = listItem ? listItem.getIcon() : ""; icon == null ? atom.resetIcon() : atom.setIcon(icon); }, /** * Sets the label inside the list to match the selected ListItem. */ __updateLabel : function() { var listItem = this.getChildControl("list").getSelection()[0]; var atom = this.getChildControl("atom"); var label = listItem ? listItem.getLabel() : ""; var format = this.getFormat(); if (format != null) { label = format.call(this, listItem); } // check for translation if (label && label.translate) { label = label.translate(); } label == null ? atom.resetLabel() : atom.setLabel(label); }, /* --------------------------------------------------------------------------- EVENT LISTENERS --------------------------------------------------------------------------- */ /** * Listener method for "mouseover" event * <ul> * <li>Adds state "hovered"</li> * <li>Removes "abandoned" and adds "pressed" state (if "abandoned" state is set)</li> * </ul> * * @param e {Event} Mouse event */ _onMouseOver : function(e) { if (!this.isEnabled() || e.getTarget() !== this) { return; } if (this.hasState("abandoned")) { this.removeState("abandoned"); this.addState("pressed"); } this.addState("hovered"); }, /** * Listener method for "mouseout" event * <ul> * <li>Removes "hovered" state</li> * <li>Adds "abandoned" and removes "pressed" state (if "pressed" state is set)</li> * </ul> * * @param e {Event} Mouse event */ _onMouseOut : function(e) { if (!this.isEnabled() || e.getTarget() !== this) { return; } this.removeState("hovered"); if (this.hasState("pressed")) { this.removeState("pressed"); this.addState("abandoned"); } }, /** * Toggles the popup's visibility. * * @param e {qx.event.type.Mouse} Mouse event */ _onClick : function(e) { this.toggle(); }, /** * Event handler for mousewheel event * * @param e {qx.event.type.Mouse} Mouse event */ _onMouseWheel : function(e) { if (this.getChildControl("popup").isVisible()) { return; } var direction = e.getWheelDelta("y") > 0 ? 1 : -1; var children = this.getSelectables(); var selected = this.getSelection()[0]; if (!selected) { selected = children[0]; } var index = children.indexOf(selected) + direction; var max = children.length - 1; // Limit if (index < 0) { index = 0; } else if (index >= max) { index = max; } this.setSelection([children[index]]); // stop the propagation // prevent any other widget from receiving this event // e.g. place a selectbox widget inside a scroll container widget e.stopPropagation(); e.preventDefault(); }, // overridden _onKeyPress : function(e) { var iden = e.getKeyIdentifier(); if(iden == "Enter" || iden == "Space") { // Apply pre-selected item (translate quick selection to real selection) if (this.__preSelectedItem) { this.setSelection([this.__preSelectedItem]); this.__preSelectedItem = null; } this.toggle(); } else { this.base(arguments, e); } }, /** * Forwards key event to list widget. * * @param e {qx.event.type.KeyInput} Key event */ _onKeyInput : function(e) { // clone the event and re-calibrate the event var clone = e.clone(); clone.setTarget(this._list); clone.setBubbles(false); // forward it to the list this.getChildControl("list").dispatchEvent(clone); }, // overridden _onListMouseDown : function(e) { // Apply pre-selected item (translate quick selection to real selection) if (this.__preSelectedItem) { this.setSelection([this.__preSelectedItem]); this.__preSelectedItem = null; } }, // overridden _onListChangeSelection : function(e) { var current = e.getData(); var old = e.getOldData(); // Remove old listeners for icon and label changes. if (old && old.length > 0) { old[0].removeListener("changeIcon", this.__updateIcon, this); old[0].removeListener("changeLabel", this.__updateLabel, this); } if (current.length > 0) { // Ignore quick context (e.g. mouseover) // and configure the new value when closing the popup afterwards var popup = this.getChildControl("popup"); var list = this.getChildControl("list"); var context = list.getSelectionContext(); if (popup.isVisible() && (context == "quick" || context == "key")) { this.__preSelectedItem = current[0]; } else { this.setSelection([current[0]]); this.__preSelectedItem = null; } // Add listeners for icon and label changes current[0].addListener("changeIcon", this.__updateIcon, this); current[0].addListener("changeLabel", this.__updateLabel, this); } else { this.resetSelection(); } }, // overridden _onPopupChangeVisibility : function(e) { this.base(arguments, e); // Synchronize the current selection to the list selection // when the popup is closed. The list selection may be invalid // because of the quick selection handling which is not // directly applied to the selectbox var popup = this.getChildControl("popup"); if (!popup.isVisible()) { var list = this.getChildControl("list"); // check if the list has any children before selecting if (list.hasChildren()) { list.setSelection(this.getSelection()); } } else { // ensure that the list is never biger that the max list height and // the available space in the viewport var distance = popup.getLayoutLocation(this); var viewPortHeight = qx.bom.Viewport.getHeight(); // distance to the bottom and top borders of the viewport var toTop = distance.top; var toBottom = viewPortHeight - distance.bottom; var availableHeigth = toTop > toBottom ? toTop : toBottom; var maxListHeight = this.getMaxListHeight(); var list = this.getChildControl("list") if (maxListHeight == null || maxListHeight > availableHeigth) { list.setMaxHeight(availableHeigth); } else if (maxListHeight < availableHeigth) { list.setMaxHeight(maxListHeight); } } } }, /* ***************************************************************************** DESTRUCT ***************************************************************************** */ destruct : function() { this.__preSelectedItem = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A Spacer is a "virtual" widget, which can be placed into any layout and takes * the space a normal widget of the same size would take. * * Spacers are invisible and very light weight because they don't require any * DOM modifications. * * *Example* * * Here is a little example of how to use the widget. * * <pre class='javascript'> * var container = new qx.ui.container.Composite(new qx.ui.layout.HBox()); * container.add(new qx.ui.core.Widget()); * container.add(new qx.ui.core.Spacer(50)); * container.add(new qx.ui.core.Widget()); * </pre> * * This example places two widgets and a spacer into a container with a * horizontal box layout. In this scenario the spacer creates an empty area of * 50 pixel width between the two widgets. * * *External Documentation* * * <a href='http://manual.qooxdoo.org/${qxversion}/pages/widget/spacer.html' target='_blank'> * Documentation of this widget in the qooxdoo manual.</a> */ qx.Class.define("qx.ui.core.Spacer", { extend : qx.ui.core.LayoutItem, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param width {Integer?null} the initial width * @param height {Integer?null} the initial height */ construct : function(width, height) { this.base(arguments); // Initialize dimensions this.setWidth(width != null ? width : 0); this.setHeight(height != null ? height : 0); }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { /** * Helper method called from the visibility queue to detect outstanding changes * to the appearance. * * @internal */ checkAppearanceNeeds : function() { // placeholder to improve compatibility with Widget. }, /** * Recursively adds all children to the given queue * * @param queue {Map} The queue to add widgets to */ addChildrenToQueue : function(queue) { // placeholder to improve compatibility with Widget. }, /** * Removes this widget from its parent and dispose it. * * Please note that the widget is not disposed synchronously. The * real dispose happens after the next queue flush. * * @return {void} */ destroy : function() { if (this.$$disposed) { return; } var parent = this.$$parent; if (parent) { parent._remove(this); } qx.ui.core.queue.Dispose.add(this); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) ************************************************************************ */ /** * A item for a list. Could be added to all List like widgets but also * to the {@link qx.ui.form.SelectBox} and {@link qx.ui.form.ComboBox}. */ qx.Class.define("qx.ui.form.ListItem", { extend : qx.ui.basic.Atom, implement : [qx.ui.form.IModel], include : [qx.ui.form.MModelProperty], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param label {String} Label to use * @param icon {String?null} Icon to use * @param model {String?null} The items value */ construct : function(label, icon, model) { this.base(arguments, label, icon); if (model != null) { this.setModel(model); } this.addListener("mouseover", this._onMouseOver, this); this.addListener("mouseout", this._onMouseOut, this); }, /* ***************************************************************************** EVENTS ***************************************************************************** */ events: { /** (Fired by {@link qx.ui.form.List}) */ "action" : "qx.event.type.Event" }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { appearance : { refine : true, init : "listitem" } }, members : { // overridden /** * @lint ignoreReferenceField(_forwardStates) */ _forwardStates : { focused : true, hovered : true, selected : true, dragover : true }, /** * Event handler for the mouse over event. */ _onMouseOver : function() { this.addState("hovered"); }, /** * Event handler for the mouse out event. */ _onMouseOut : function() { this.removeState("hovered"); } }, destruct : function() { this.removeListener("mouseover", this._onMouseOver, this); this.removeListener("mouseout", this._onMouseOut, this); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * This interface defines the necessary features a form renderer should have. * Keep in mind that all renderes has to be widgets. */ qx.Interface.define("qx.ui.form.renderer.IFormRenderer", { members : { /** * Add a group of form items with the corresponding names. The names should * be displayed as hint for the user what to do with the form item. * The title is optional and can be used as grouping for the given form * items. * * @param items {qx.ui.core.Widget[]} An array of form items to render. * @param names {String[]} An array of names for the form items. * @param title {String?} A title of the group you are adding. * @param itemsOptions {Array?null} The added additional data. * @param headerOptions {Map?null} The options map as defined by the form * for the current group header. */ addItems : function(items, names, title, itemsOptions, headerOptions) {}, /** * Adds a button the form renderer. * * @param button {qx.ui.form.Button} A button which should be added to * the form. * @param options {Map?null} The added additional data. */ addButton : function(button, options) {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Abstract renderer for {@link qx.ui.form.Form}. This abstract rendere should * be the superclass of all form renderer. It takes the form, which is * supplied as constructor parameter and configures itself. So if you need to * set some additional information on your renderer before adding the widgets, * be sure to do that before calling this.base(arguments, form). */ qx.Class.define("qx.ui.form.renderer.AbstractRenderer", { type : "abstract", extend : qx.ui.core.Widget, implement : qx.ui.form.renderer.IFormRenderer, /** * @param form {qx.ui.form.Form} The form to render. */ construct : function(form) { this.base(arguments); this._visibilityBindingIds = []; this._labels = []; // translation support if (qx.core.Environment.get("qx.dynlocale")) { qx.locale.Manager.getInstance().addListener( "changeLocale", this._onChangeLocale, this ); this._names = []; } // add the groups var groups = form.getGroups(); for (var i = 0; i < groups.length; i++) { var group = groups[i]; this.addItems( group.items, group.labels, group.title, group.options, group.headerOptions ); } // add the buttons var buttons = form.getButtons(); var buttonOptions = form.getButtonOptions(); for (var i = 0; i < buttons.length; i++) { this.addButton(buttons[i], buttonOptions[i]); } }, members : { _names : null, _visibilityBindingIds : null, _labels : null, /** * Helper to bind the item's visibility to the label's visibility. * @param item {qx.ui.core.Widget} The form element. * @param label {qx.ui.basic.Label} The label for the form element. */ _connectVisibility : function(item, label) { // map the items visibility to the label var id = item.bind("visibility", label, "visibility"); this._visibilityBindingIds.push({id: id, item: item}); }, /** * Locale change event handler * * @signature function(e) * @param e {Event} the change event */ _onChangeLocale : qx.core.Environment.select("qx.dynlocale", { "true" : function(e) { for (var i = 0; i < this._names.length; i++) { var entry = this._names[i]; if (entry.name && entry.name.translate) { entry.name = entry.name.translate(); } var newText = this._createLabelText(entry.name, entry.item); entry.label.setValue(newText); }; }, "false" : null }), /** * Creates the label text for the given form item. * * @param name {String} The content of the label without the * trailing * and : * @param item {qx.ui.form.IForm} The item, which has the required state. * @return {String} The text for the given item. */ _createLabelText : function(name, item) { var required = ""; if (item.getRequired()) { required = " <span style='color:red'>*</span> "; } // Create the label. Append a colon only if there's text to display. var colon = name.length > 0 || item.getRequired() ? " :" : ""; return name + required + colon; }, // interface implementation addItems : function(items, names, title) { throw new Error("Abstract method call"); }, // interface implementation addButton : function(button) { throw new Error("Abstract method call"); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { if (qx.core.Environment.get("qx.dynlocale")) { qx.locale.Manager.getInstance().removeListener("changeLocale", this._onChangeLocale, this); } this._names = null; // remove all created lables for (var i=0; i < this._labels.length; i++) { this._labels[i].dispose(); }; // remove the visibility bindings for (var i = 0; i < this._visibilityBindingIds.length; i++) { var entry = this._visibilityBindingIds[i]; entry.item.removeBinding(entry.id); }; } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Single column renderer for {@link qx.ui.form.Form}. */ qx.Class.define("qx.ui.form.renderer.Single", { extend : qx.ui.form.renderer.AbstractRenderer, construct : function(form) { var layout = new qx.ui.layout.Grid(); layout.setSpacing(6); layout.setColumnFlex(0, 1); layout.setColumnAlign(0, "right", "top"); this._setLayout(layout); this.base(arguments, form); }, members : { _row : 0, _buttonRow : null, /** * Add a group of form items with the corresponding names. The names are * displayed as label. * The title is optional and is used as grouping for the given form * items. * * @param items {qx.ui.core.Widget[]} An array of form items to render. * @param names {String[]} An array of names for the form items. * @param title {String?} A title of the group you are adding. */ addItems : function(items, names, title) { // add the header if (title != null) { this._add( this._createHeader(title), {row: this._row, column: 0, colSpan: 2} ); this._row++; } // add the items for (var i = 0; i < items.length; i++) { var label = this._createLabel(names[i], items[i]); this._add(label, {row: this._row, column: 0}); var item = items[i]; label.setBuddy(item); this._add(item, {row: this._row, column: 1}); this._row++; this._connectVisibility(item, label); // store the names for translation if (qx.core.Environment.get("qx.dynlocale")) { this._names.push({name: names[i], label: label, item: items[i]}); } } }, /** * Adds a button the form renderer. All buttons will be added in a * single row at the bottom of the form. * * @param button {qx.ui.form.Button} The button to add. */ addButton : function(button) { if (this._buttonRow == null) { // create button row this._buttonRow = new qx.ui.container.Composite(); this._buttonRow.setMarginTop(5); var hbox = new qx.ui.layout.HBox(); hbox.setAlignX("right"); hbox.setSpacing(5); this._buttonRow.setLayout(hbox); // add the button row this._add(this._buttonRow, {row: this._row, column: 0, colSpan: 2}); // increase the row this._row++; } // add the button this._buttonRow.add(button); }, /** * Returns the set layout for configuration. * * @return {qx.ui.layout.Grid} The grid layout of the widget. */ getLayout : function() { return this._getLayout(); }, /** * Creates a label for the given form item. * * @param name {String} The content of the label without the * trailing * and : * @param item {qx.ui.core.Widget} The item, which has the required state. * @return {qx.ui.basic.Label} The label for the given item. */ _createLabel : function(name, item) { var label = new qx.ui.basic.Label(this._createLabelText(name, item)); // store lables for disposal this._labels.push(label); label.setRich(true); label.setAppearance("form-renderer-label"); return label; }, /** * Creates a header label for the form groups. * * @param title {String} Creates a header label. * @return {qx.ui.basic.Label} The header for the form groups. */ _createHeader : function(title) { var header = new qx.ui.basic.Label(title); // store lables for disposal this._labels.push(header); header.setFont("bold"); if (this._row != 0) { header.setMarginTop(10); } header.setAlignX("left"); return header; } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { // first, remove all buttons from the button row because they // should not be disposed if (this._buttonRow) { this._buttonRow.removeAll(); this._disposeObjects("_buttonRow"); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Mixin for the selection in the data binding controller. * It contains an selection property which can be manipulated. * Remember to call the method {@link #_addChangeTargetListener} on every * change of the target. * It is also important that the elements stored in the target e.g. ListItems * do have the corresponding model stored as user data under the "model" key. */ qx.Mixin.define("qx.data.controller.MSelection", { /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ construct : function() { // check for a target property if (!qx.Class.hasProperty(this.constructor, "target")) { throw new Error("Target property is needed."); } // create a default selection array if (this.getSelection() == null) { this.__ownSelection = new qx.data.Array(); this.setSelection(this.__ownSelection); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * Data array containing the selected model objects. This property can be * manipulated directly which means that a push to the selection will also * select the corresponding element in the target. */ selection : { check: "qx.data.Array", event: "changeSelection", apply: "_applySelection", init: null } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { // private members // // set the semaphore-like variable for the selection change _modifingSelection : 0, __selectionListenerId : null, __selectionArrayListenerId : null, __ownSelection : null, /* --------------------------------------------------------------------------- APPLY METHODS --------------------------------------------------------------------------- */ /** * Apply-method for setting a new selection array. Only the change listener * will be removed from the old array and added to the new. * * @param value {qx.data.Array} The new data array for the selection. * @param old {qx.data.Array|null} The old data array for the selection. */ _applySelection: function(value, old) { // remove the old listener if necessary if (this.__selectionArrayListenerId != undefined && old != undefined) { old.removeListenerById(this.__selectionArrayListenerId); } // add a new change listener to the changeArray this.__selectionArrayListenerId = value.addListener( "change", this.__changeSelectionArray, this ); // apply the new selection this._updateSelection(); }, /* --------------------------------------------------------------------------- EVENT HANDLER --------------------------------------------------------------------------- */ /** * Event handler for the change of the data array holding the selection. * If a change is in the selection array, the selection update will be * invoked. */ __changeSelectionArray: function() { this._updateSelection(); }, /** * Event handler for a change in the target selection. * If the selection in the target has changed, the selected model objects * will be found and added to the selection array. */ _changeTargetSelection: function() { // dont do anything without a target if (this.getTarget() == null) { return; } // if a selection API is supported if (!this.__targetSupportsMultiSelection() && !this.__targetSupportsSingleSelection()) { return; } // if __changeSelectionArray is currently working, do nothing if (this._inSelectionModification()) { return; } // get both selections var targetSelection = this.getTarget().getSelection(); var selection = this.getSelection(); if (selection == null) { selection = new qx.data.Array(); this.__ownSelection = selection; this.setSelection(selection); } // go through the target selection var spliceArgs = [0, selection.getLength()]; for (var i = 0; i < targetSelection.length; i++) { spliceArgs.push(targetSelection[i].getModel()); } // use splice to ensure a correct change event [BUG #4728] selection.splice.apply(selection, spliceArgs).dispose(); // fire the change event manually this.fireDataEvent("changeSelection", this.getSelection()); }, /* --------------------------------------------------------------------------- SELECTION --------------------------------------------------------------------------- */ /** * Helper method which should be called by the classes including this * Mixin when the target changes. * * @param value {qx.ui.core.Widget|null} The new target. * @param old {qx.ui.core.Widget|null} The old target. */ _addChangeTargetListener: function(value, old) { // remove the old selection listener if (this.__selectionListenerId != undefined && old != undefined) { old.removeListenerById(this.__selectionListenerId); } if (value != null) { // if a selection API is supported if ( this.__targetSupportsMultiSelection() || this.__targetSupportsSingleSelection() ) { // add a new selection listener this.__selectionListenerId = value.addListener( "changeSelection", this._changeTargetSelection, this ); } } }, /** * Method for updating the selection. It checks for the case of single or * multi selection and after that checks if the selection in the selection * array is the same as in the target widget. */ _updateSelection: function() { // do not update if no target is given if (!this.getTarget()) { return; } // mark the change process in a flag this._startSelectionModification(); // if its a multi selection target if (this.__targetSupportsMultiSelection()) { var targetSelection = []; // go through the selection array for (var i = 0; i < this.getSelection().length; i++) { // store each item var model = this.getSelection().getItem(i); var selectable = this.__getSelectableForModel(model); if (selectable != null) { targetSelection.push(selectable); } } this.getTarget().setSelection(targetSelection); // get the selection of the target targetSelection = this.getTarget().getSelection(); // get all items selected in the list var targetSelectionItems = []; for (var i = 0; i < targetSelection.length; i++) { targetSelectionItems[i] = targetSelection[i].getModel(); } // go through the controller selection for (var i = this.getSelection().length - 1; i >= 0; i--) { // if the item in the controller selection is not selected in the list if (!qx.lang.Array.contains( targetSelectionItems, this.getSelection().getItem(i) )) { // remove the current element and get rid of the return array this.getSelection().splice(i, 1).dispose(); } } // if its a single selection target } else if (this.__targetSupportsSingleSelection()) { // get the model which should be selected var item = this.getSelection().getItem(this.getSelection().length - 1); if (item !== undefined) { // select the last selected item (old selection will be removed anyway) this.__selectItem(item); // remove the other items from the selection data array and get // rid of the return array this.getSelection().splice( 0, this.getSelection().getLength() - 1 ).dispose(); } else { // if there is no item to select (e.g. new model set [BUG #4125]), // reset the selection this.getTarget().resetSelection(); } } // reset the changing flag this._endSelectionModification(); }, /** * Helper-method returning true, if the target supports multi selection. * @return {boolean} true, if the target supports multi selection. */ __targetSupportsMultiSelection: function() { var targetClass = this.getTarget().constructor; return qx.Class.implementsInterface(targetClass, qx.ui.core.IMultiSelection); }, /** * Helper-method returning true, if the target supports single selection. * @return {boolean} true, if the target supports single selection. */ __targetSupportsSingleSelection: function() { var targetClass = this.getTarget().constructor; return qx.Class.implementsInterface(targetClass, qx.ui.core.ISingleSelection); }, /** * Internal helper for selecting an item in the target. The item to select * is defined by a given model item. * * @param item {qx.core.Object} A model element. */ __selectItem: function(item) { var selectable = this.__getSelectableForModel(item); // if no selectable could be found, just return if (selectable == null) { return; } // if the target is multi selection able if (this.__targetSupportsMultiSelection()) { // select the item in the target this.getTarget().addToSelection(selectable); // if the target is single selection able } else if (this.__targetSupportsSingleSelection()) { this.getTarget().setSelection([selectable]); } }, /** * Returns the list item storing the given model in its model property. * * @param model {var} The representing model of a selectable. */ __getSelectableForModel : function(model) { // get all list items var children = this.getTarget().getSelectables(true); // go through all children and search for the child to select for (var i = 0; i < children.length; i++) { if (children[i].getModel() == model) { return children[i]; } } // if no selectable was found return null; }, /** * Helper-Method signaling that currently the selection of the target is * in change. That will block the change of the internal selection. * {@link #_endSelectionModification} */ _startSelectionModification: function() { this._modifingSelection++; }, /** * Helper-Method signaling that the internal changing of the targets * selection is over. * {@link #_startSelectionModification} */ _endSelectionModification: function() { this._modifingSelection > 0 ? this._modifingSelection-- : null; }, /** * Helper-Method for checking the state of the selection modification. * {@link #_startSelectionModification} * {@link #_endSelectionModification} */ _inSelectionModification: function() { return this._modifingSelection > 0; } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { if (this.__ownSelection) { this.__ownSelection.dispose(); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * <h2>List Controller</h2> * * *General idea* * The list controller is responsible for synchronizing every list like widget * with a data array. It does not matter if the array contains atomic values * like strings of complete objects where one property holds the value for * the label and another property holds the icon url. You can even use converts * the make the label show a text corresponding to the icon by binding both, * label and icon to the same model property and converting one. * * *Features* * * * Synchronize the model and the target * * Label and icon are bindable * * Takes care of the selection * * Passes on the options used by the bindings * * *Usage* * * As model, only {@link qx.data.Array}s do work. The currently supported * targets are * * * {@link qx.ui.form.SelectBox} * * {@link qx.ui.form.List} * * {@link qx.ui.form.ComboBox} * * All the properties like model, target or any property path is bindable. * Especially the model is nice to bind to another selection for example. * The controller itself can only work if it has a model and a target set. The * rest of the properties may be empty. * * *Cross reference* * * * If you want to bind single values, use {@link qx.data.controller.Object} * * If you want to bind a tree widget, use {@link qx.data.controller.Tree} * * If you want to bind a form widget, use {@link qx.data.controller.Form} */ qx.Class.define("qx.data.controller.List", { extend : qx.core.Object, include: qx.data.controller.MSelection, implement : qx.data.controller.ISelection, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param model {qx.data.Array?null} The array containing the data. * * @param target {qx.ui.core.Widget?null} The widget which should show the * ListItems. * * @param labelPath {String?null} If the model contains objects, the labelPath * is the path reference to the property in these objects which should be * shown as label. */ construct : function(model, target, labelPath) { this.base(arguments); // lookup table for filtering and sorting this.__lookupTable = []; // register for bound target properties and onUpdate methods // from the binding options this.__boundProperties = []; this.__boundPropertiesReverse = []; this.__onUpdate = {}; if (labelPath != null) { this.setLabelPath(labelPath); } if (model != null) { this.setModel(model); } if (target != null) { this.setTarget(target); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** Data array containing the data which should be shown in the list. */ model : { check: "qx.data.IListData", apply: "_applyModel", event: "changeModel", nullable: true, dereference: true }, /** The target widget which should show the data. */ target : { apply: "_applyTarget", event: "changeTarget", nullable: true, init: null, dereference: true }, /** * The path to the property which holds the information that should be * shown as a label. This is only needed if objects are stored in the model. */ labelPath : { check: "String", apply: "_applyLabelPath", nullable: true }, /** * The path to the property which holds the information that should be * shown as an icon. This is only needed if objects are stored in the model * and if the icon should be shown. */ iconPath : { check: "String", apply: "_applyIconPath", nullable: true }, /** * A map containing the options for the label binding. The possible keys * can be found in the {@link qx.data.SingleValueBinding} documentation. */ labelOptions : { apply: "_applyLabelOptions", nullable: true }, /** * A map containing the options for the icon binding. The possible keys * can be found in the {@link qx.data.SingleValueBinding} documentation. */ iconOptions : { apply: "_applyIconOptions", nullable: true }, /** * Delegation object, which can have one or more functions defined by the * {@link IControllerDelegate} interface. */ delegate : { apply: "_applyDelegate", event: "changeDelegate", init: null, nullable: true } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { // private members __changeModelListenerId : null, __lookupTable : null, __onUpdate : null, __boundProperties : null, __boundPropertiesReverse : null, __syncTargetSelection : null, __syncModelSelection : null, /* --------------------------------------------------------------------------- PUBLIC API --------------------------------------------------------------------------- */ /** * Updates the filter and the target. This could be used if the filter * uses an additional parameter which changes the filter result. */ update: function() { this.__changeModelLength(); this.__renewBindings(); this._updateSelection(); }, /* --------------------------------------------------------------------------- APPLY METHODS --------------------------------------------------------------------------- */ /** * If a new delegate is set, it applies the stored configuration for the * list items to the already created list items once. * * @param value {qx.core.Object|null} The new delegate. * @param old {qx.core.Object|null} The old delegate. */ _applyDelegate: function(value, old) { this._setConfigureItem(value, old); this._setFilter(value, old); this._setCreateItem(value, old); this._setBindItem(value, old); }, /** * Apply-method which will be called if the icon options has been changed. * It invokes a renewing of all set bindings. * * @param value {Map|null} The new icon options. * @param old {Map|null} The old icon options. */ _applyIconOptions: function(value, old) { this.__renewBindings(); }, /** * Apply-method which will be called if the label options has been changed. * It invokes a renewing of all set bindings. * * @param value {Map|null} The new label options. * @param old {Map|null} The old label options. */ _applyLabelOptions: function(value, old) { this.__renewBindings(); }, /** * Apply-method which will be called if the icon path has been changed. * It invokes a renewing of all set bindings. * * @param value {String|null} The new icon path. * @param old {String|null} The old icon path. */ _applyIconPath: function(value, old) { this.__renewBindings(); }, /** * Apply-method which will be called if the label path has been changed. * It invokes a renewing of all set bindings. * * @param value {String|null} The new label path. * @param old {String|null} The old label path. */ _applyLabelPath: function(value, old) { this.__renewBindings(); }, /** * Apply-method which will be called if the model has been changed. It * removes all the listeners from the old model and adds the needed * listeners to the new model. It also invokes the initial filling of the * target widgets if there is a target set. * * @param value {qx.data.Array|null} The new model array. * @param old {qx.data.Array|null} The old model array. */ _applyModel: function(value, old) { // remove the old listener if (old != undefined) { if (this.__changeModelListenerId != undefined) { old.removeListenerById(this.__changeModelListenerId); } } // erase the selection if there is something selected if (this.getSelection() != undefined && this.getSelection().length > 0) { this.getSelection().splice(0, this.getSelection().length).dispose(); } // if a model is set if (value != null) { // add a new listener this.__changeModelListenerId = value.addListener("change", this.__changeModel, this); // renew the index lookup table this.__buildUpLookupTable(); // check for the new length this.__changeModelLength(); // as we only change the labels of the items, the selection change event // may be missing so we invoke it here if (old == null) { this._changeTargetSelection(); } else { // update the selection asynchronously this.__syncTargetSelection = true; qx.ui.core.queue.Widget.add(this); } } else { var target = this.getTarget(); // if the model is set to null, we should remove all items in the target if (target != null) { // we need to remove the bindings too so use the controller method // for removing items var length = target.getChildren().length; for (var i = 0; i < length; i++) { this.__removeItem(); }; } } }, /** * Apply-method which will be called if the target has been changed. * When the target changes, every binding needs to be reset and the old * target needs to be cleaned up. If there is a model, the target will be * filled with the data of the model. * * @param value {qx.ui.core.Widget|null} The new target. * @param old {qx.ui.core.Widget|null} The old target. */ _applyTarget: function(value, old) { // add a listener for the target change this._addChangeTargetListener(value, old); // if there was an old target if (old != undefined) { // remove all element of the old target var removed = old.removeAll(); for (var i=0; i<removed.length; i++) { removed[i].destroy(); } // remove all bindings this.removeAllBindings(); } if (value != null) { if (this.getModel() != null) { // add a binding for all elements in the model for (var i = 0; i < this.__lookupTable.length; i++) { this.__addItem(this.__lookup(i)); } } } }, /* --------------------------------------------------------------------------- EVENT HANDLER --------------------------------------------------------------------------- */ /** * Event handler for the change event of the model. If the model changes, * Only the selection needs to be changed. The change of the data will * be done by the binding. */ __changeModel: function() { // need an asynchronous selection update because the bindings have to be // executed to update the selection probably (using the widget queue) // this.__syncTargetSelection = true; this.__syncModelSelection = true; qx.ui.core.queue.Widget.add(this); // update on filtered lists... (bindings need to be renewed) if (this.__lookupTable.length != this.getModel().getLength()) { this.update(); } }, /** * Internal method used to sync the selection. The controller uses the * widget queue to schedule the selection update. An asynchronous handling of * the selection is needed because the bindings (event listeners for the * binding) need to be executed before the selection is updated. * @internal */ syncWidget : function() { if (this.__syncTargetSelection) { this._changeTargetSelection(); } if (this.__syncModelSelection) { this._updateSelection(); } this.__syncModelSelection = this.__syncTargetSelection = null; }, /** * Event handler for the changeLength of the model. If the length changes * of the model, either ListItems need to be removed or added to the target. */ __changeModelLength: function() { // only do something if there is a target if (this.getTarget() == null) { return; } // build up the look up table this.__buildUpLookupTable(); // get the length var newLength = this.__lookupTable.length; var currentLength = this.getTarget().getChildren().length; // if there are more item if (newLength > currentLength) { // add the new elements for (var j = currentLength; j < newLength; j++) { this.__addItem(this.__lookup(j)); } // if there are less elements } else if (newLength < currentLength) { // remove the unnecessary items for (var j = currentLength; j > newLength; j--) { this.__removeItem(); } } // sync the target selection in case someone deleted a item in // selection mode "one" [BUG #4839] this.__syncTargetSelection = true; qx.ui.core.queue.Widget.add(this); }, /** * Helper method which removes and adds the change listener of the * controller to the model. This is sometimes necessary to ensure that the * listener of the controller is executed as the last listener of the chain. */ __moveChangeListenerAtTheEnd : function() { var model = this.getModel(); // it can be that the bindings has been reset without the model so // maybe there is no model in some scenarios if (model != null) { model.removeListenerById(this.__changeModelListenerId); this.__changeModelListenerId = model.addListener("change", this.__changeModel, this); } }, /* --------------------------------------------------------------------------- ITEM HANDLING --------------------------------------------------------------------------- */ /** * Creates a ListItem and delegates the configure method if a delegate is * set and the needed function (configureItem) is available. * * @return {qx.ui.form.ListItem} The created and configured ListItem. */ _createItem: function() { var delegate = this.getDelegate(); // check if a delegate and a create method is set if (delegate != null && delegate.createItem != null) { var item = delegate.createItem(); } else { var item = new qx.ui.form.ListItem(); } // if there is a configure method, invoke it if (delegate != null && delegate.configureItem != null) { delegate.configureItem(item); } return item; }, /** * Internal helper to add ListItems to the target including the creation * of the binding. * * @param index {Number} The index of the item to add. */ __addItem: function(index) { // create a new ListItem var listItem = this._createItem(); // set up the binding this._bindListItem(listItem, index); // add the ListItem to the target this.getTarget().add(listItem); }, /** * Internal helper to remove ListItems from the target. Also the binding * will be removed properly. */ __removeItem: function() { this._startSelectionModification(); var children = this.getTarget().getChildren(); // get the last binding id var index = children.length - 1; // get the item var oldItem = children[index]; this._removeBindingsFrom(oldItem); // remove the item this.getTarget().removeAt(index); oldItem.destroy(); this._endSelectionModification(); }, /** * Returns all models currently visible by the list. This method is only * useful if you use the filter via the {@link #delegate}. * * @return {qx.data.Array} A new data array container all the models * which representation items are currently visible. */ getVisibleModels : function() { var visibleModels = []; var target = this.getTarget(); if (target != null) { var items = target.getChildren(); for (var i = 0; i < items.length; i++) { visibleModels.push(items[i].getModel()); }; } return new qx.data.Array(visibleModels); }, /* --------------------------------------------------------------------------- BINDING STUFF --------------------------------------------------------------------------- */ /** * Sets up the binding for the given ListItem and index. * * @param item {qx.ui.form.ListItem} The internally created and used * ListItem. * @param index {Number} The index of the ListItem. */ _bindListItem: function(item, index) { var delegate = this.getDelegate(); // if a delegate for creating the binding is given, use it if (delegate != null && delegate.bindItem != null) { delegate.bindItem(this, item, index); // otherwise, try to bind the listItem by default } else { this.bindDefaultProperties(item, index); } }, /** * Helper-Method for binding the default properties (label, icon and model) * from the model to the target widget. * * This method should only be called in the * {@link qx.data.controller.IControllerDelegate#bindItem} function * implemented by the {@link #delegate} property. * * @param item {qx.ui.form.ListItem} The internally created and used * ListItem. * @param index {Number} The index of the ListItem. */ bindDefaultProperties : function(item, index) { // model this.bindProperty( "", "model", null, item, index ); // label this.bindProperty( this.getLabelPath(), "label", this.getLabelOptions(), item, index ); // if the iconPath is set if (this.getIconPath() != null) { this.bindProperty( this.getIconPath(), "icon", this.getIconOptions(), item, index ); } }, /** * Helper-Method for binding a given property from the model to the target * widget. * This method should only be called in the * {@link qx.data.controller.IControllerDelegate#bindItem} function * implemented by the {@link #delegate} property. * * @param sourcePath {String | null} The path to the property in the model. * If you use an empty string, the whole model item will be bound. * @param targetProperty {String} The name of the property in the target * widget. * @param options {Map | null} The options to use for the binding. * @param targetWidget {qx.ui.core.Widget} The target widget. * @param index {Number} The index of the current binding. */ bindProperty: function(sourcePath, targetProperty, options, targetWidget, index) { // create the options for the binding containing the old options // including the old onUpdate function if (options != null) { var options = qx.lang.Object.clone(options); this.__onUpdate[targetProperty] = options.onUpdate; delete options.onUpdate; } else { options = {}; this.__onUpdate[targetProperty] = null; } options.onUpdate = qx.lang.Function.bind(this._onBindingSet, this, index); // build up the path for the binding var bindPath = "model[" + index + "]"; if (sourcePath != null && sourcePath != "") { bindPath += "." + sourcePath; } // create the binding var id = this.bind(bindPath, targetWidget, targetProperty, options); targetWidget.setUserData(targetProperty + "BindingId", id); // save the bound property if (!qx.lang.Array.contains(this.__boundProperties, targetProperty)) { this.__boundProperties.push(targetProperty); } }, /** * Helper-Method for binding a given property from the target widget to * the model. * This method should only be called in the * {@link qx.data.controller.IControllerDelegate#bindItem} function * implemented by the {@link #delegate} property. * * @param targetPath {String | null} The path to the property in the model. * @param sourcePath {String} The name of the property in the target. * @param options {Map | null} The options to use for the binding. * @param sourceWidget {qx.ui.core.Widget} The source widget. * @param index {Number} The index of the current binding. */ bindPropertyReverse: function( targetPath, sourcePath, options, sourceWidget, index ) { // build up the path for the binding var targetBindPath = "model[" + index + "]"; if (targetPath != null && targetPath != "") { targetBindPath += "." + targetPath; } // create the binding var id = sourceWidget.bind(sourcePath, this, targetBindPath, options); sourceWidget.setUserData(targetPath + "ReverseBindingId", id); // save the bound property if (!qx.lang.Array.contains(this.__boundPropertiesReverse, targetPath)) { this.__boundPropertiesReverse.push(targetPath); } }, /** * Method which will be called on the invoke of every binding. It takes * care of the selection on the change of the binding. * * @param index {Number} The index of the current binding. * @param sourceObject {qx.core.Object} The source object of the binding. * @param targetObject {qx.core.Object} The target object of the binding. */ _onBindingSet: function(index, sourceObject, targetObject) { // ignore the binding set if the model is already set to null if (this.getModel() == null || this._inSelectionModification()) { return; } // go through all bound target properties for (var i = 0; i < this.__boundProperties.length; i++) { // if there is an onUpdate for one of it, invoke it if (this.__onUpdate[this.__boundProperties[i]] != null) { this.__onUpdate[this.__boundProperties[i]](); } } }, /** * Internal helper method to remove the binding of the given item. * * @param item {Number} The item of which the binding which should * be removed. */ _removeBindingsFrom: function(item) { // go through all bound target properties for (var i = 0; i < this.__boundProperties.length; i++) { // get the binding id and remove it, if possible var id = item.getUserData(this.__boundProperties[i] + "BindingId"); if (id != null) { this.removeBinding(id); } } // go through all reverse bound properties for (var i = 0; i < this.__boundPropertiesReverse.length; i++) { // get the binding id and remove it, if possible var id = item.getUserData( this.__boundPropertiesReverse[i] + "ReverseBindingId" ); if (id != null) { item.removeBinding(id); } }; }, /** * Internal helper method to renew all set bindings. */ __renewBindings: function() { // ignore, if no target is set (startup) if (this.getTarget() == null || this.getModel() == null) { return; } // get all children of the target var items = this.getTarget().getChildren(); // go through all items for (var i = 0; i < items.length; i++) { this._removeBindingsFrom(items[i]); // add the new binding this._bindListItem(items[i], this.__lookup(i)); } // move the controllers change handler for the model to the end of the // listeners queue this.__moveChangeListenerAtTheEnd(); }, /* --------------------------------------------------------------------------- DELEGATE HELPER --------------------------------------------------------------------------- */ /** * Helper method for applying the delegate It checks if a configureItem * is set end invokes the initial process to apply the given function. * * @param value {Object} The new delegate. * @param old {Object} The old delegate. */ _setConfigureItem: function(value, old) { if (value != null && value.configureItem != null && this.getTarget() != null) { var children = this.getTarget().getChildren(); for (var i = 0; i < children.length; i++) { value.configureItem(children[i]); } } }, /** * Helper method for applying the delegate It checks if a bindItem * is set end invokes the initial process to apply the given function. * * @param value {Object} The new delegate. * @param old {Object} The old delegate. */ _setBindItem: function(value, old) { // if a new bindItem function is set if (value != null && value.bindItem != null) { // do nothing if the bindItem function did not change if (old != null && old.bindItem != null && value.bindItem == old.bindItem) { return; } this.__renewBindings(); } }, /** * Helper method for applying the delegate It checks if a createItem * is set end invokes the initial process to apply the given function. * * @param value {Object} The new delegate. * @param old {Object} The old delegate. */ _setCreateItem: function(value, old) { if ( this.getTarget() == null || this.getModel() == null || value == null || value.createItem == null ) { return; } this._startSelectionModification(); // remove all bindings var children = this.getTarget().getChildren(); for (var i = 0, l = children.length; i < l; i++) { this._removeBindingsFrom(children[i]); } // remove all elements of the target var removed = this.getTarget().removeAll(); for (var i=0; i<removed.length; i++) { removed[i].destroy(); } // update this.update(); this._endSelectionModification(); this._updateSelection(); }, /** * Apply-Method for setting the filter. It removes all bindings, * check if the length has changed and adds or removes the items in the * target. After that, the bindings will be set up again and the selection * will be updated. * * @param value {Function|null} The new filter function. * @param old {Function|null} The old filter function. */ _setFilter: function(value, old) { // update the filter if it has been removed if ((value == null || value.filter == null) && (old != null && old.filter != null)) { this.__removeFilter(); } // check if it is necessary to do anything if ( this.getTarget() == null || this.getModel() == null || value == null || value.filter == null ) { return; } // if yes, continue this._startSelectionModification(); // remove all bindings var children = this.getTarget().getChildren(); for (var i = 0, l = children.length; i < l; i++) { this._removeBindingsFrom(children[i]); } // store the old lookup table var oldTable = this.__lookupTable; // generate a new lookup table this.__buildUpLookupTable(); // if there are lesser items if (oldTable.length > this.__lookupTable.length) { // remove the unnecessary items for (var j = oldTable.length; j > this.__lookupTable.length; j--) { this.getTarget().removeAt(j - 1).destroy(); } // if there are more items } else if (oldTable.length < this.__lookupTable.length) { // add the new elements for (var j = oldTable.length; j < this.__lookupTable.length; j++) { var tempItem = this._createItem(); this.getTarget().add(tempItem); } } // bind every list item again var listItems = this.getTarget().getChildren(); for (var i = 0; i < listItems.length; i++) { this._bindListItem(listItems[i], this.__lookup(i)); } // move the controllers change handler for the model to the end of the // listeners queue this.__moveChangeListenerAtTheEnd(); this._endSelectionModification(); this._updateSelection(); }, /** * This helper is responsible for removing the filter and setting the * controller to a valid state without a filtering. */ __removeFilter : function() { // renew the index lookup table this.__buildUpLookupTable(); // check for the new length this.__changeModelLength(); // renew the bindings this.__renewBindings(); // need an asynchronous selection update because the bindings have to be // executed to update the selection probably (using the widget queue) this.__syncModelSelection = true; qx.ui.core.queue.Widget.add(this); }, /* --------------------------------------------------------------------------- LOOKUP STUFF --------------------------------------------------------------------------- */ /** * Helper-Method which builds up the index lookup for the filter feature. * If no filter is set, the lookup table will be a 1:1 mapping. */ __buildUpLookupTable: function() { var model = this.getModel(); if (model == null) { return; } var delegate = this.getDelegate(); if (delegate != null) { var filter = delegate.filter; } this.__lookupTable = []; for (var i = 0; i < model.getLength(); i++) { if (filter == null || filter(model.getItem(i))) { this.__lookupTable.push(i); } } }, /** * Function for accessing the lookup table. * * @param index {Integer} The index of the lookup table. */ __lookup: function(index) { return this.__lookupTable[index]; } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this.__lookupTable = this.__onUpdate = this.__boundProperties = null; this.__boundPropertiesReverse = null; // remove yourself from the widget queue qx.ui.core.queue.Widget.remove(this); } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * <h2>Form Controller</h2> * * *General idea* * * The form controller is responsible for connecting a form with a model. If no * model is given, a model can be created. This created model will fit exactly * to the given form and can be used for serialization. All the connections * between the form items and the model are handled by an internal * {@link qx.data.controller.Object}. * * *Features* * * * Connect a form to a model (bidirectional) * * Create a model for a given form * * *Usage* * * The controller only works if both a controller and a model are set. * Creating a model will automatically set the created model. * * *Cross reference* * * * If you want to bind single values, use {@link qx.data.controller.Object} * * If you want to bind a list like widget, use {@link qx.data.controller.List} * * If you want to bind a tree widget, use {@link qx.data.controller.Tree} */ qx.Class.define("qx.data.controller.Form", { extend : qx.core.Object, /** * @param model {qx.core.Object | null} The model to bind the target to. The * given object will be set as {@link #model} property. * @param target {qx.ui.form.Form | null} The form which contains the form * items. The given form will be set as {@link #target} property. * @param selfUpdate {Boolean?false} If set to true, you need to call the * {@link #updateModel} method to get the data in the form to the model. * Otherwise, the data will be synced automatically on every change of * the form. */ construct : function(model, target, selfUpdate) { this.base(arguments); this._selfUpdate = !!selfUpdate; this.__bindingOptions = {}; if (model != null) { this.setModel(model); } if (target != null) { this.setTarget(target); } }, properties : { /** Data object containing the data which should be shown in the target. */ model : { check: "qx.core.Object", apply: "_applyModel", event: "changeModel", nullable: true, dereference: true }, /** The target widget which should show the data. */ target : { check: "qx.ui.form.Form", apply: "_applyTarget", event: "changeTarget", nullable: true, init: null, dereference: true } }, members : { __objectController : null, __bindingOptions : null, /** * The form controller uses for setting up the bindings the fundamental * binding layer, the {@link qx.data.SingleValueBinding}. To achieve a * binding in both directions, two bindings are neede. With this method, * you have the opportunity to set the options used for the bindings. * * @param name {String} The name of the form item for which the options * should be used. * @param model2target {Map} Options map used for the binding from model * to target. The possible options can be found in the * {@link qx.data.SingleValueBinding} class. * @param target2model {Map} Options map used for the binding from target * to model. The possible options can be found in the * {@link qx.data.SingleValueBinding} class. */ addBindingOptions : function(name, model2target, target2model) { this.__bindingOptions[name] = [model2target, target2model]; // return if not both, model and target are given if (this.getModel() == null || this.getTarget() == null) { return; } // renew the affected binding var item = this.getTarget().getItems()[name]; var targetProperty = this.__isModelSelectable(item) ? "modelSelection[0]" : "value"; // remove the binding this.__objectController.removeTarget(item, targetProperty, name); // set up the new binding with the options this.__objectController.addTarget( item, targetProperty, name, !this._selfUpdate, model2target, target2model ); }, /** * Creates and sets a model using the {@link qx.data.marshal.Json} object. * Remember that this method can only work if the form is set. The created * model will fit exactly that form. Changing the form or adding an item to * the form will need a new model creation. * * @param includeBubbleEvents {Boolean} Whether the model should support * the bubbling of change events or not. * @return {qx.core.Object} The created model. */ createModel : function(includeBubbleEvents) { var target = this.getTarget(); // throw an error if no target is set if (target == null) { throw new Error("No target is set."); } var items = target.getItems(); var data = {}; for (var name in items) { var names = name.split("."); var currentData = data; for (var i = 0; i < names.length; i++) { // if its the last item if (i + 1 == names.length) { // check if the target is a selection var clazz = items[name].constructor; var itemValue = null; if (qx.Class.hasInterface(clazz, qx.ui.core.ISingleSelection)) { // use the first element of the selection because passed to the // marshaler (and its single selection anyway) [BUG #3541] itemValue = items[name].getModelSelection().getItem(0) || null; } else { itemValue = items[name].getValue(); } // call the converter if available [BUG #4382] if (this.__bindingOptions[name] && this.__bindingOptions[name][1]) { itemValue = this.__bindingOptions[name][1].converter(itemValue); } currentData[names[i]] = itemValue; } else { // if its not the last element, check if the object exists if (!currentData[names[i]]) { currentData[names[i]] = {}; } currentData = currentData[names[i]]; } } } var model = qx.data.marshal.Json.createModel(data, includeBubbleEvents); this.setModel(model); return model; }, /** * Responsible for synching the data from entered in the form to the model. * Please keep in mind that this method only works if you create the form * with <code>selfUpdate</code> set to true. Otherwise, this method will * do nothing because updates will be synched automatically on every * change. */ updateModel: function(){ // only do stuff if self update is enabled and a model or target is set if (!this._selfUpdate || !this.getModel() || !this.getTarget()) { return; } var items = this.getTarget().getItems(); for (var name in items) { var item = items[name]; var sourceProperty = this.__isModelSelectable(item) ? "modelSelection[0]" : "value"; var options = this.__bindingOptions[name]; options = options && this.__bindingOptions[name][1]; qx.data.SingleValueBinding.updateTarget( item, sourceProperty, this.getModel(), name, options ); } }, // apply method _applyTarget : function(value, old) { // if an old target is given, remove the binding if (old != null) { this.__tearDownBinding(old); } // do nothing if no target is set if (this.getModel() == null) { return; } // target and model are available if (value != null) { this.__setUpBinding(); } }, // apply method _applyModel : function(value, old) { // first, get rid off all bindings (avoids whong data population) if (this.__objectController != null) { var items = this.getTarget().getItems(); for (var name in items) { var item = items[name]; var targetProperty = this.__isModelSelectable(item) ? "modelSelection[0]" : "value"; this.__objectController.removeTarget(item, targetProperty, name); } } // set the model of the object controller if available if (this.__objectController != null) { this.__objectController.setModel(value); } // do nothing is no target is set if (this.getTarget() == null) { return; } // model and target are available if (value != null) { this.__setUpBinding(); } }, /** * Internal helper for setting up the bindings using * {@link qx.data.controller.Object#addTarget}. All bindings are set * up bidirectional. */ __setUpBinding : function() { // create the object controller if (this.__objectController == null) { this.__objectController = new qx.data.controller.Object(this.getModel()); } // get the form items var items = this.getTarget().getItems(); // connect all items for (var name in items) { var item = items[name]; var targetProperty = this.__isModelSelectable(item) ? "modelSelection[0]" : "value"; var options = this.__bindingOptions[name]; // try to bind all given items in the form try { if (options == null) { this.__objectController.addTarget(item, targetProperty, name, !this._selfUpdate); } else { this.__objectController.addTarget( item, targetProperty, name, !this._selfUpdate, options[0], options[1] ); } // ignore not working items } catch (ex) { if (qx.core.Environment.get("qx.debug")) { this.warn("Could not bind property " + name + " of " + this.getModel()); } } } // make sure the initial values of the model are taken for resetting [BUG #5874] this.getTarget().redefineResetter(); }, /** * Internal helper for removing all set up bindings using * {@link qx.data.controller.Object#removeTarget}. * * @param oldTarget {qx.ui.form.Form} The form which has been removed. */ __tearDownBinding : function(oldTarget) { // do nothing if the object controller has not been created if (this.__objectController == null) { return; } // get the items var items = oldTarget.getItems(); // disconnect all items for (var name in items) { var item = items[name]; var targetProperty = this.__isModelSelectable(item) ? "modelSelection[0]" : "value"; this.__objectController.removeTarget(item, targetProperty, name); } }, /** * Returns whether the given item implements * {@link qx.ui.core.ISingleSelection} and * {@link qx.ui.form.IModelSelection}. * * @param item {qx.ui.form.IForm} The form item to check. * * @return {true} true, if given item fits. */ __isModelSelectable : function(item) { return qx.Class.hasInterface(item.constructor, qx.ui.core.ISingleSelection) && qx.Class.hasInterface(item.constructor, qx.ui.form.IModelSelection); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { // dispose the object controller because the bindings need to be removed if (this.__objectController) { this.__objectController.dispose(); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Defines the methods needed by every marshaler which should work with the * qooxdoo data stores. */ qx.Interface.define("qx.data.marshal.IMarshaler", { members : { /** * Creates for the given data the needed classes. The classes contain for * every key in the data a property. The classname is always the prefix * <code>qx.data.model</code>. Two objects containing the same keys will not * create two different classes. * * @param data {Object} The object for which classes should be created. * @param includeBubbleEvents {Boolean} Whether the model should support * the bubbling of change events or not. */ toClass : function(data, includeBubbleEvents) {}, /** * Creates for the given data the needed models. Be sure to have the classes * created with {@link #toClass} before calling this method. * * @param data {Object} The object for which models should be created. * * @return {qx.core.Object} The created model object. */ toModel : function(data) {} } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * This class is responsible for converting json data to class instances * including the creation of the classes. */ qx.Class.define("qx.data.marshal.Json", { extend : qx.core.Object, implement : [qx.data.marshal.IMarshaler], /** * @param delegate {Object} An object containing one of the methods described * in {@link qx.data.marshal.IMarshalerDelegate}. */ construct : function(delegate) { this.base(arguments); this.__delegate = delegate; }, statics : { $$instance : null, /** * Creates a qooxdoo object based on the given json data. This function * is just a static wrapper. If you want to configure the creation * process of the class, use {@link qx.data.marshal.Json} directly. * * @param data {Object} The object for which classes should be created. * @param includeBubbleEvents {Boolean} Whether the model should support * the bubbling of change events or not. * * @return {qx.core.Object} An instance of the corresponding class. */ createModel : function(data, includeBubbleEvents) { // singleton for the json marshaler if (this.$$instance === null) { this.$$instance = new qx.data.marshal.Json(); } // be sure to create the classes first this.$$instance.toClass(data, includeBubbleEvents); // return the model return this.$$instance.toModel(data); } }, members : { __delegate : null, /** * Converts a given object into a hash which will be used to identify the * classes under the namespace <code>qx.data.model</code>. * * @param data {Object} The JavaScript object from which the hash is * required. * @return {String} The hash representation of the given JavaScript object. */ __jsonToHash: function(data) { return qx.Bootstrap.getKeys(data).sort().join('"'); }, /** * Creates for the given data the needed classes. The classes contain for * every key in the data a property. The classname is always the prefix * <code>qx.data.model</code> and the hash of the data created by * {@link #__jsonToHash}. Two objects containing the same keys will not * create two different classes. The class creation process also supports * the functions provided by its delegate. * * Important, please keep in mind that only valid JavaScript identifiers * can be used as keys in the data map. For convenience '-' in keys will * be removed (a-b will be ab in the end). * * @see qx.data.store.IStoreDelegate * * @param data {Object} The object for which classes should be created. * @param includeBubbleEvents {Boolean} Whether the model should support * the bubbling of change events or not. */ toClass: function(data, includeBubbleEvents) { // break on all primitive json types and qooxdoo objects if ( !qx.lang.Type.isObject(data) || !!data.$$isString // check for localized strings || data instanceof qx.core.Object ) { // check for arrays if (data instanceof Array || qx.Bootstrap.getClass(data) == "Array") { for (var i = 0; i < data.length; i++) { this.toClass(data[i], includeBubbleEvents); } } // ignore arrays and primitive types return; } var hash = this.__jsonToHash(data); // check for the possible child classes for (var key in data) { this.toClass(data[key], includeBubbleEvents); } // class already exists if (qx.Class.isDefined("qx.data.model." + hash)) { return; } // class is defined by the delegate if ( this.__delegate && this.__delegate.getModelClass && this.__delegate.getModelClass(hash) != null ) { return; } // create the properties map var properties = {}; // include the disposeItem for the dispose process. var members = {__disposeItem : this.__disposeItem}; for (var key in data) { // apply the property names mapping if (this.__delegate && this.__delegate.getPropertyMapping) { key = this.__delegate.getPropertyMapping(key, hash); } // stip the unwanted characters key = key.replace(/-|\.|\s+/g, ""); // check for valid JavaScript identifier (leading numbers are ok) if (qx.core.Environment.get("qx.debug")) { this.assertTrue((/^[$0-9A-Za-z_]*$/).test(key), "The key '" + key + "' is not a valid JavaScript identifier.") } properties[key] = {}; properties[key].nullable = true; properties[key].event = "change" + qx.lang.String.firstUp(key); // bubble events if (includeBubbleEvents) { properties[key].apply = "_applyEventPropagation"; } // validation rules if (this.__delegate && this.__delegate.getValidationRule) { var rule = this.__delegate.getValidationRule(hash, key); if (rule) { properties[key].validate = "_validate" + key; members["_validate" + key] = rule; } } } // try to get the superclass, qx.core.Object as default if (this.__delegate && this.__delegate.getModelSuperClass) { var superClass = this.__delegate.getModelSuperClass(hash) || qx.core.Object; } else { var superClass = qx.core.Object; } // try to get the mixins var mixins = []; if (this.__delegate && this.__delegate.getModelMixins) { var delegateMixins = this.__delegate.getModelMixins(hash); // check if its an array if (!qx.lang.Type.isArray(delegateMixins)) { if (delegateMixins != null) { mixins = [delegateMixins]; } } else { mixins = delegateMixins; } } // include the mixin for the event bubbling if (includeBubbleEvents) { mixins.push(qx.data.marshal.MEventBubbling); } // create the map for the class var newClass = { extend : superClass, include : mixins, properties : properties, members : members, destruct : this.__disposeProperties }; qx.Class.define("qx.data.model." + hash, newClass); }, /** * Destructor for all created classes which disposes all stuff stored in * the properties. */ __disposeProperties : function() { var properties = qx.util.PropertyUtil.getAllProperties(this.constructor); for (var desc in properties) { this.__disposeItem(this.get(properties[desc].name)); }; }, /** * Helper for disposing items of the created class. * * @param item {var} The item to dispose. */ __disposeItem : function(item) { if (!(item instanceof qx.core.Object)) { // ignore all non objects return; } // ignore already disposed items (could happen during shutdown) if (item.isDisposed()) { return; } item.dispose(); }, /** * Creates an instance for the given data hash. * * @param hash {String} The hash of the data for which an instance should * be created. * @return {qx.core.Object} An instance of the corresponding class. */ __createInstance: function(hash) { var delegateClass; // get the class from the delegate if (this.__delegate && this.__delegate.getModelClass) { delegateClass = this.__delegate.getModelClass(hash); } if (delegateClass != null) { return (new delegateClass()); } else { var clazz = qx.Class.getByName("qx.data.model." + hash); return (new clazz()); } }, /** * Creates for the given data the needed models. Be sure to have the classes * created with {@link #toClass} before calling this method. The creation * of the class itself is delegated to the {@link #__createInstance} method, * which could use the {@link qx.data.store.IStoreDelegate} methods, if * given. * * @param data {Object} The object for which models should be created. * * @return {qx.core.Object} The created model object. */ toModel: function(data) { var isObject = qx.lang.Type.isObject(data); var isArray = data instanceof Array || qx.Bootstrap.getClass(data) == "Array"; if ( (!isObject && !isArray) || !!data.$$isString // check for localized strings || data instanceof qx.core.Object ) { return data; } else if (isArray) { var array = new qx.data.Array(); // set the auto dispose for the array array.setAutoDisposeItems(true); for (var i = 0; i < data.length; i++) { array.push(this.toModel(data[i])); } return array; } else if (isObject) { // create an instance for the object var hash = this.__jsonToHash(data); var model = this.__createInstance(hash); // go threw all element in the data for (var key in data) { // apply the property names mapping var propertyName = key; if (this.__delegate && this.__delegate.getPropertyMapping) { propertyName = this.__delegate.getPropertyMapping(key, hash); } var propertyNameReplaced = propertyName.replace(/-|\.|\s+/g, ""); // warn if there has been a replacement if ( (qx.core.Environment.get("qx.debug")) && qx.core.Environment.get("qx.debug.databinding") ) { if (propertyNameReplaced != propertyName) { this.warn( "The model contained an illegal name: '" + key + "'. Replaced it with '" + propertyName + "'." ); } } propertyName = propertyNameReplaced; // only set the properties if they are available [BUG #5909] var setterName = "set" + qx.lang.String.firstUp(propertyName); if (model[setterName]) { model[setterName](this.toModel(data[key])); } } return model; } throw new Error("Unsupported type!"); } }, /* ***************************************************************************** DESTRUCT ***************************************************************************** */ destruct : function() { this.__delegate = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * <h2>Object Controller</h2> * * *General idea* * * The idea of the object controller is to make the binding of one model object * containing one or more properties as easy as possible. Therefore the * controller can take a model as property. Every property in that model can be * bound to one or more target properties. The binding will be for * atomic types only like Numbers, Strings, ... * * *Features* * * * Manages the bindings between the model properties and the different targets * * No need for the user to take care of the binding ids * * Can create an bidirectional binding (read- / write-binding) * * Handles the change of the model which means adding the old targets * * *Usage* * * The controller only can work if a model is set. If the model property is * null, the controller is not working. But it can be null on any time. * * *Cross reference* * * * If you want to bind a list like widget, use {@link qx.data.controller.List} * * If you want to bind a tree widget, use {@link qx.data.controller.Tree} * * If you want to bind a form widget, use {@link qx.data.controller.Form} */ qx.Class.define("qx.data.controller.Object", { extend : qx.core.Object, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param model {qx.core.Object?null} The model for the model property. */ construct : function(model) { this.base(arguments); // create a map for all created binding ids this.__bindings = {}; // create an array to store all current targets this.__targets = []; if (model != null) { this.setModel(model); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** The model object which does have the properties for the binding. */ model : { check: "qx.core.Object", event: "changeModel", apply: "_applyModel", nullable: true, dereference: true } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { // private members __targets : null, __bindings : null, /** * Apply-method which will be called if a new model has been set. * All bindings will be moved to the new model. * * @param value {qx.core.Object|null} The new model. * @param old {qx.core.Object|null} The old model. */ _applyModel: function(value, old) { // for every target for (var i = 0; i < this.__targets.length; i++) { // get the properties var targetObject = this.__targets[i][0]; var targetProperty = this.__targets[i][1]; var sourceProperty = this.__targets[i][2]; var bidirectional = this.__targets[i][3]; var options = this.__targets[i][4]; var reverseOptions = this.__targets[i][5]; // remove it from the old if possible if (old != undefined && !old.isDisposed()) { this.__removeTargetFrom(targetObject, targetProperty, sourceProperty, old); } // add it to the new if available if (value != undefined) { this.__addTarget( targetObject, targetProperty, sourceProperty, bidirectional, options, reverseOptions ); } else { // in shutdown situations, it may be that something is already // disposed [BUG #4343] if (targetObject.isDisposed() || qx.core.ObjectRegistry.inShutDown) { continue; } // if the model is null, reset the current target if (targetProperty.indexOf("[") == -1) { targetObject["reset" + qx.lang.String.firstUp(targetProperty)](); } else { var open = targetProperty.indexOf("["); var index = parseInt( targetProperty.substring(open + 1, targetProperty.length - 1), 10 ); targetProperty = targetProperty.substring(0, open); var targetArray = targetObject["get" + qx.lang.String.firstUp(targetProperty)](); if (index == "last") { index = targetArray.length; } if (targetArray) { targetArray.setItem(index, null); } } } } }, /** * Adds a new target to the controller. After adding the target, the given * property of the model will be bound to the targets property. * * @param targetObject {qx.core.Object} The object on which the property * should be bound. * * @param targetProperty {String} The property to which the binding should * go. * * @param sourceProperty {String} The name of the property in the model. * * @param bidirectional {Boolean?false} Signals if the binding should also work * in the reverse direction, from the target to source. * * @param options {Map?null} The options Map used by the binding from source * to target. The possible options can be found in the * {@link qx.data.SingleValueBinding} class. * * @param reverseOptions {Map?null} The options used by the binding in the * reverse direction. The possible options can be found in the * {@link qx.data.SingleValueBinding} class. */ addTarget: function( targetObject, targetProperty, sourceProperty, bidirectional, options, reverseOptions ) { // store the added target this.__targets.push([ targetObject, targetProperty, sourceProperty, bidirectional, options, reverseOptions ]); // delegate the adding this.__addTarget( targetObject, targetProperty, sourceProperty, bidirectional, options, reverseOptions ); }, /** * Does the work for {@link #addTarget} but without saving the target * to the internal target registry. * * @param targetObject {qx.core.Object} The object on which the property * should be bound. * * @param targetProperty {String} The property to which the binding should * go. * * @param sourceProperty {String} The name of the property in the model. * * @param bidirectional {Boolean?false} Signals if the binding should also work * in the reverse direction, from the target to source. * * @param options {Map?null} The options Map used by the binding from source * to target. The possible options can be found in the * {@link qx.data.SingleValueBinding} class. * * @param reverseOptions {Map?null} The options used by the binding in the * reverse direction. The possible options can be found in the * {@link qx.data.SingleValueBinding} class. */ __addTarget: function( targetObject, targetProperty, sourceProperty, bidirectional, options, reverseOptions ) { // do nothing if no model is set if (this.getModel() == null) { return; } // create the binding var id = this.getModel().bind( sourceProperty, targetObject, targetProperty, options ); // create the reverse binding if necessary var idReverse = null if (bidirectional) { idReverse = targetObject.bind( targetProperty, this.getModel(), sourceProperty, reverseOptions ); } // save the binding var targetHash = targetObject.toHashCode(); if (this.__bindings[targetHash] == undefined) { this.__bindings[targetHash] = []; } this.__bindings[targetHash].push( [id, idReverse, targetProperty, sourceProperty, options, reverseOptions] ); }, /** * Removes the target identified by the three properties. * * @param targetObject {qx.core.Object} The target object on which the * binding exist. * * @param targetProperty {String} The targets property name used by the * adding of the target. * * @param sourceProperty {String} The name of the property of the model. */ removeTarget: function(targetObject, targetProperty, sourceProperty) { this.__removeTargetFrom( targetObject, targetProperty, sourceProperty, this.getModel() ); // delete the target in the targets reference for (var i = 0; i < this.__targets.length; i++) { if ( this.__targets[i][0] == targetObject && this.__targets[i][1] == targetProperty && this.__targets[i][2] == sourceProperty ) { this.__targets.splice(i, 1); } } }, /** * Does the work for {@link #removeTarget} but without removing the target * from the internal registry. * * @param targetObject {qx.core.Object} The target object on which the * binding exist. * * @param targetProperty {String} The targets property name used by the * adding of the target. * * @param sourceProperty {String} The name of the property of the model. * * @param sourceObject {String} The source object from which the binding * comes. */ __removeTargetFrom: function( targetObject, targetProperty, sourceProperty, sourceObject ) { // check for not fitting targetObjects if (!(targetObject instanceof qx.core.Object)) { // just do nothing return; } var currentListing = this.__bindings[targetObject.toHashCode()]; // if no binding is stored if (currentListing == undefined || currentListing.length == 0) { return; } // go threw all listings for the object for (var i = 0; i < currentListing.length; i++) { // if it is the listing if ( currentListing[i][2] == targetProperty && currentListing[i][3] == sourceProperty ) { // remove the binding var id = currentListing[i][0]; sourceObject.removeBinding(id); // check for the reverse binding if (currentListing[i][1] != null) { targetObject.removeBinding(currentListing[i][1]); } // delete the entry and return currentListing.splice(i, 1); return; } } } }, /* ***************************************************************************** DESTRUCT ***************************************************************************** */ destruct : function() { // set the model to null to get the bindings removed if (this.getModel() != null && !this.getModel().isDisposed()) { this.setModel(null); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) ************************************************************************ */ /** * Tango icons */ qx.Theme.define("qx.theme.icon.Tango", { title : "Tango", aliases : { "icon" : "qx/icon/Tango" } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A very complex decoration using two, partly combined and clipped images * to render a graphically impressive borders with gradients. * * The decoration supports all forms of vertical gradients. The gradients must * be stretchable to support different heights. * * The edges could use different styles of rounded borders. Even different * edge sizes are supported. The sizes are automatically detected by * the build system using the image meta data. * * The decoration uses clipped images to reduce the number of external * resources to load. */ qx.Class.define("qx.ui.decoration.Grid", { extend: qx.core.Object, implement : [qx.ui.decoration.IDecorator], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param baseImage {String} Base image to use * @param insets {Integer|Array} Insets for the grid */ construct : function(baseImage, insets) { this.base(arguments); if (qx.ui.decoration.css3.BorderImage.IS_SUPPORTED) { this.__impl = new qx.ui.decoration.css3.BorderImage(); if (baseImage) { this.__setBorderImage(baseImage); } } else { this.__impl = new qx.ui.decoration.GridDiv(baseImage); } if (insets != null) { this.__impl.setInsets(insets); } // ignore the internal used implementation in the dispose debugging [BUG #5343] if (qx.core.Environment.get("qx.debug.dispose")) { this.__impl.$$ignoreDisposeWarning = true; } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * Base image URL. There must be an image with this name and the sliced * and the nine sliced images. The sliced images must be named according to * the following scheme: * * ${baseImageWithoutExtension}-${imageName}.${baseImageExtension} * * These image names are used: * * * tl (top-left edge) * * t (top side) * * tr (top-right edge) * * bl (bottom-left edge) * * b (bottom side) * * br (bottom-right edge) * * * l (left side) * * c (center image) * * r (right side) */ baseImage : { check : "String", nullable : true, apply : "_applyBaseImage" }, /** Width of the left inset (keep this margin to the outer box) */ insetLeft : { check : "Number", nullable: true, apply : "_applyInsets" }, /** Width of the right inset (keep this margin to the outer box) */ insetRight : { check : "Number", nullable: true, apply : "_applyInsets" }, /** Width of the bottom inset (keep this margin to the outer box) */ insetBottom : { check : "Number", nullable: true, apply : "_applyInsets" }, /** Width of the top inset (keep this margin to the outer box) */ insetTop : { check : "Number", nullable: true, apply : "_applyInsets" }, /** Property group for insets */ insets : { group : [ "insetTop", "insetRight", "insetBottom", "insetLeft" ], mode : "shorthand" }, /** Width of the left slice */ sliceLeft : { check : "Number", nullable: true, apply : "_applySlices" }, /** Width of the right slice */ sliceRight : { check : "Number", nullable: true, apply : "_applySlices" }, /** Width of the bottom slice */ sliceBottom : { check : "Number", nullable: true, apply : "_applySlices" }, /** Width of the top slice */ sliceTop : { check : "Number", nullable: true, apply : "_applySlices" }, /** Property group for slices */ slices : { group : [ "sliceTop", "sliceRight", "sliceBottom", "sliceLeft" ], mode : "shorthand" }, /** Only used for the CSS3 implementation, see {@link qx.ui.decoration.css3.BorderImage#fill} **/ fill : { apply : "_applyFill" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __impl : null, // interface implementation getMarkup : function() { return this.__impl.getMarkup(); }, // interface implementation resize : function(element, width, height) { this.__impl.resize(element, width, height); }, // interface implementation tint : function(element, bgcolor) { // do nothing }, // interface implementation getInsets : function() { return this.__impl.getInsets(); }, // property apply _applyInsets : function(value, old, name) { var setter = "set" + qx.lang.String.firstUp(name); this.__impl[setter](value); }, // property apply _applySlices : function(value, old, name) { var setter = "set" + qx.lang.String.firstUp(name); // The GridDiv implementation doesn't have slice properties, // slices are obtained from the sizes of the images instead if (this.__impl[setter]) { this.__impl[setter](value); } }, //property apply _applyFill : function(value, old, name) { if (this.__impl.setFill) { this.__impl.setFill(value); } }, // property apply _applyBaseImage : function(value, old) { if (this.__impl instanceof qx.ui.decoration.GridDiv) { this.__impl.setBaseImage(value); } else { this.__setBorderImage(value); } }, /** * Configures the border image decorator * * @param baseImage {String} URL of the base image */ __setBorderImage : function(baseImage) { this.__impl.setBorderImage(baseImage); var base = qx.util.AliasManager.getInstance().resolve(baseImage); var split = /(.*)(\.[a-z]+)$/.exec(base); var prefix = split[1]; var ext = split[2]; var ResourceManager = qx.util.ResourceManager.getInstance(); var topSlice = ResourceManager.getImageHeight(prefix + "-t" + ext); var rightSlice = ResourceManager.getImageWidth(prefix + "-r" + ext); var bottomSlice = ResourceManager.getImageHeight(prefix + "-b" + ext); var leftSlice = ResourceManager.getImageWidth(prefix + "-l" + ext); if (qx.core.Environment.get("qx.debug") && !this.__impl instanceof qx.ui.decoration.css3.BorderImage) { var assertMessageTop = "The value of the property 'topSlice' is null! " + "Please verify the image '" + prefix + "-t" + ext + "' is present."; var assertMessageRight = "The value of the property 'rightSlice' is null! " + "Please verify the image '" + prefix + "-r" + ext + "' is present."; var assertMessageBottom = "The value of the property 'bottomSlice' is null! " + "Please verify the image '" + prefix + "-b" + ext + "' is present."; var assertMessageLeft = "The value of the property 'leftSlice' is null! " + "Please verify the image '" + prefix + "-l" + ext + "' is present."; qx.core.Assert.assertNotNull(topSlice, assertMessageTop); qx.core.Assert.assertNotNull(rightSlice, assertMessageRight); qx.core.Assert.assertNotNull(bottomSlice, assertMessageBottom); qx.core.Assert.assertNotNull(leftSlice, assertMessageLeft); } if (topSlice && rightSlice && bottomSlice && leftSlice) { this.__impl.setSlice([topSlice, rightSlice, bottomSlice, leftSlice]); } } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this.__impl.dispose(); this.__impl = null; } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * Decorator, which uses the CSS3 border image properties. * * This decorator can be used as replacement for {@link qx.ui.layout.Grid}, * {@link qx.ui.layout.HBox} and {@link qx.ui.layout.VBox} decorators in * browsers, which support it. * * Supported browsers are: * <ul> * <li>Firefox >= 3.5</li> * <li>Safari >= 4</li> * <li>Chrome >= 3</li> * <ul> */ qx.Class.define("qx.ui.decoration.css3.BorderImage", { extend : qx.ui.decoration.Abstract, /** * @param borderImage {String} Base image to use * @param slice {Integer|Array} Sets the {@link #slice} property */ construct : function(borderImage, slice) { this.base(arguments); // Initialize properties if (borderImage != null) { this.setBorderImage(borderImage); } if (slice != null) { this.setSlice(slice); } }, statics : { /** * Whether the browser supports this decorator */ IS_SUPPORTED : qx.bom.element.Style.isPropertySupported("borderImage") }, properties : { /** * Base image URL. */ borderImage : { check : "String", nullable : true, apply : "_applyStyle" }, /** * The top slice line of the base image. The slice properties divide the * image into nine regions, which define the corner, edge and the center * images. */ sliceTop : { check : "Integer", init : 0, apply : "_applyStyle" }, /** * The right slice line of the base image. The slice properties divide the * image into nine regions, which define the corner, edge and the center * images. */ sliceRight : { check : "Integer", init : 0, apply : "_applyStyle" }, /** * The bottom slice line of the base image. The slice properties divide the * image into nine regions, which define the corner, edge and the center * images. */ sliceBottom : { check : "Integer", init : 0, apply : "_applyStyle" }, /** * The left slice line of the base image. The slice properties divide the * image into nine regions, which define the corner, edge and the center * images. */ sliceLeft : { check : "Integer", init : 0, apply : "_applyStyle" }, /** * The slice properties divide the image into nine regions, which define the * corner, edge and the center images. */ slice : { group : [ "sliceTop", "sliceRight", "sliceBottom", "sliceLeft" ], mode : "shorthand" }, /** * This property specifies how the images for the sides and the middle part * of the border image are scaled and tiled horizontally. * * Values have the following meanings: * <ul> * <li><strong>stretch</strong>: The image is stretched to fill the area.</li> * <li><strong>repeat</strong>: The image is tiled (repeated) to fill the area.</li> * <li><strong>round</strong>: The image is tiled (repeated) to fill the area. If it does not * fill the area with a whole number of tiles, the image is rescaled so * that it does.</li> * </ul> */ repeatX : { check : ["stretch", "repeat", "round"], init : "stretch", apply : "_applyStyle" }, /** * This property specifies how the images for the sides and the middle part * of the border image are scaled and tiled vertically. * * Values have the following meanings: * <ul> * <li><strong>stretch</strong>: The image is stretched to fill the area.</li> * <li><strong>repeat</strong>: The image is tiled (repeated) to fill the area.</li> * <li><strong>round</strong>: The image is tiled (repeated) to fill the area. If it does not * fill the area with a whole number of tiles, the image is rescaled so * that it does.</li> * </ul> */ repeatY : { check : ["stretch", "repeat", "round"], init : "stretch", apply : "_applyStyle" }, /** * This property specifies how the images for the sides and the middle part * of the border image are scaled and tiled. */ repeat : { group : ["repeatX", "repeatY"], mode : "shorthand" }, /** * If set to <code>false</code>, the center image will be omitted and only * the border will be drawn. */ fill : { check : "Boolean", init : true } }, members : { __markup : null, // overridden _getDefaultInsets : function() { return { top : 0, right : 0, bottom : 0, left : 0 }; }, // overridden _isInitialized: function() { return !!this.__markup; }, /* --------------------------------------------------------------------------- INTERFACE IMPLEMENTATION --------------------------------------------------------------------------- */ // interface implementation getMarkup : function() { if (this.__markup) { return this.__markup; } var source = this._resolveImageUrl(this.getBorderImage()); var slice = [ this.getSliceTop(), this.getSliceRight(), this.getSliceBottom(), this.getSliceLeft() ]; var repeat = [ this.getRepeatX(), this.getRepeatY() ].join(" ") var fill = this.getFill() && qx.core.Environment.get("css.borderimage.standardsyntax") ? " fill" : ""; this.__markup = [ "<div style='", qx.bom.element.Style.compile({ "borderImage" : 'url("' + source + '") ' + slice.join(" ") + fill + " " + repeat, "borderStyle" : "solid", "borderColor" : "transparent", position: "absolute", lineHeight: 0, fontSize: 0, overflow: "hidden", boxSizing: "border-box", borderWidth: slice.join("px ") + "px" }), ";'></div>" ].join(""); // Store return this.__markup; }, // interface implementation resize : function(element, width, height) { element.style.width = width + "px"; element.style.height = height + "px"; }, // interface implementation tint : function(element, bgcolor) { // not implemented }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyStyle : function(value, old, name) { if (qx.core.Environment.get("qx.debug")) { if (this._isInitialized()) { throw new Error("This decorator is already in-use. Modification is not possible anymore!"); } } }, /** * Resolve the url of the given image * * @param image {String} base image URL * @return {String} the resolved image URL */ _resolveImageUrl : function(image) { return qx.util.ResourceManager.getInstance().toUri( qx.util.AliasManager.getInstance().resolve(image) ); } }, destruct : function() { this.__markup = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A very complex decoration using two, partly combined and clipped images * to render a graphically impressive borders with gradients. * * The decoration supports all forms of vertical gradients. The gradients must * be stretchable to support different heights. * * The edges could use different styles of rounded borders. Even different * edge sizes are supported. The sizes are automatically detected by * the build system using the image meta data. * * The decoration uses clipped images to reduce the number of external * resources to load. */ qx.Class.define("qx.ui.decoration.GridDiv", { extend : qx.ui.decoration.Abstract, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param baseImage {String} Base image to use * @param insets {Integer|Array} Insets for the grid */ construct : function(baseImage, insets) { this.base(arguments); // Initialize properties if (baseImage != null) { this.setBaseImage(baseImage); } if (insets != null) { this.setInsets(insets); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * Base image URL. All the different images needed are named by the default * naming scheme: * * ${baseImageWithoutExtension}-${imageName}.${baseImageExtension} * * These image names are used: * * * tl (top-left edge) * * t (top side) * * tr (top-right edge) * * bl (bottom-left edge) * * b (bottom side) * * br (bottom-right edge) * * * l (left side) * * c (center image) * * r (right side) */ baseImage : { check : "String", nullable : true, apply : "_applyBaseImage" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { _markup : null, _images : null, _edges : null, // overridden _getDefaultInsets : function() { return { top : 0, right : 0, bottom : 0, left : 0 }; }, // overridden _isInitialized: function() { return !!this._markup; }, /* --------------------------------------------------------------------------- INTERFACE IMPLEMENTATION --------------------------------------------------------------------------- */ // interface implementation getMarkup : function() { if (this._markup) { return this._markup; } var Decoration = qx.bom.element.Decoration; var images = this._images; var edges = this._edges; // Create edges and vertical sides // Order: tl, t, tr, bl, b, bt, l, c, r var html = []; // Outer frame // Note: Overflow=hidden is needed for Safari 3.1 to omit scrolling through // dragging when the cursor is in the text field in Spinners etc. html.push('<div style="position:absolute;top:0;left:0;overflow:hidden;font-size:0;line-height:0;">'); // Top: left, center, right html.push(Decoration.create(images.tl, "no-repeat", { top: 0, left: 0 })); html.push(Decoration.create(images.t, "scale-x", { top: 0, left: edges.left + "px" })); html.push(Decoration.create(images.tr, "no-repeat", { top: 0, right : 0 })); // Bottom: left, center, right html.push(Decoration.create(images.bl, "no-repeat", { bottom: 0, left:0 })); html.push(Decoration.create(images.b, "scale-x", { bottom: 0, left: edges.left + "px" })); html.push(Decoration.create(images.br, "no-repeat", { bottom: 0, right: 0 })); // Middle: left, center, right html.push(Decoration.create(images.l, "scale-y", { top: edges.top + "px", left: 0 })); html.push(Decoration.create(images.c, "scale", { top: edges.top + "px", left: edges.left + "px" })); html.push(Decoration.create(images.r, "scale-y", { top: edges.top + "px", right: 0 })); // Outer frame html.push('</div>'); // Store return this._markup = html.join(""); }, // interface implementation resize : function(element, width, height) { // Compute inner sizes var edges = this._edges; var innerWidth = width - edges.left - edges.right; var innerHeight = height - edges.top - edges.bottom; // Set the inner width or height to zero if negative if (innerWidth < 0) {innerWidth = 0;} if (innerHeight < 0) {innerHeight = 0;} // Update nodes element.style.width = width + "px"; element.style.height = height + "px"; element.childNodes[1].style.width = innerWidth + "px"; element.childNodes[4].style.width = innerWidth + "px"; element.childNodes[7].style.width = innerWidth + "px"; element.childNodes[6].style.height = innerHeight + "px"; element.childNodes[7].style.height = innerHeight + "px"; element.childNodes[8].style.height = innerHeight + "px"; if ((qx.core.Environment.get("engine.name") == "mshtml")) { // Internet Explorer as of version 6 or version 7 in quirks mode // have rounding issues when working with odd dimensions: // right and bottom positioned elements are rendered with a // one pixel negative offset which results into some ugly // render effects. if ( parseFloat(qx.core.Environment.get("engine.version")) < 7 || (qx.core.Environment.get("browser.quirksmode") && parseFloat(qx.core.Environment.get("engine.version")) < 8) ) { if (width%2==1) { element.childNodes[2].style.marginRight = "-1px"; element.childNodes[5].style.marginRight = "-1px"; element.childNodes[8].style.marginRight = "-1px"; } else { element.childNodes[2].style.marginRight = "0px"; element.childNodes[5].style.marginRight = "0px"; element.childNodes[8].style.marginRight = "0px"; } if (height%2==1) { element.childNodes[3].style.marginBottom = "-1px"; element.childNodes[4].style.marginBottom = "-1px"; element.childNodes[5].style.marginBottom = "-1px"; } else { element.childNodes[3].style.marginBottom = "0px"; element.childNodes[4].style.marginBottom = "0px"; element.childNodes[5].style.marginBottom = "0px"; } } } }, // interface implementation tint : function(element, bgcolor) { // not implemented }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyBaseImage : function(value, old) { if (qx.core.Environment.get("qx.debug")) { if (this._markup) { throw new Error("This decorator is already in-use. Modification is not possible anymore!"); } } if (value) { var base = this._resolveImageUrl(value); var split = /(.*)(\.[a-z]+)$/.exec(base); var prefix = split[1]; var ext = split[2]; // Store images var images = this._images = { tl : prefix + "-tl" + ext, t : prefix + "-t" + ext, tr : prefix + "-tr" + ext, bl : prefix + "-bl" + ext, b : prefix + "-b" + ext, br : prefix + "-br" + ext, l : prefix + "-l" + ext, c : prefix + "-c" + ext, r : prefix + "-r" + ext }; // Store edges this._edges = this._computeEdgeSizes(images); } }, /** * Resolve the url of the given image * * @param image {String} base image URL * @return {String} the resolved image URL */ _resolveImageUrl : function(image) { return qx.util.AliasManager.getInstance().resolve(image); }, /** * Returns the sizes of the "top" and "bottom" heights and the "left" and * "right" widths of the grid. * * @param images {Map} Map of image URLs * @return {Map} the edge sizes */ _computeEdgeSizes : function(images) { var ResourceManager = qx.util.ResourceManager.getInstance(); return { top : ResourceManager.getImageHeight(images.t), bottom : ResourceManager.getImageHeight(images.b), left : ResourceManager.getImageWidth(images.l), right : ResourceManager.getImageWidth(images.r) }; } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this._markup = this._images = this._edges = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2010 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Mixin for the border radius CSS property. * This mixin is usually used by {@link qx.ui.decoration.DynamicDecorator}. * * Keep in mind that this is not supported by all browsers: * * * Firefox 3,5+ * * IE9+ * * Safari 3.0+ * * Opera 10.5+ * * Chrome 4.0+ */ qx.Mixin.define("qx.ui.decoration.MBorderRadius", { properties : { /** top left corner radius */ radiusTopLeft : { nullable : true, check : "Integer", apply : "_applyBorderRadius" }, /** top right corner radius */ radiusTopRight : { nullable : true, check : "Integer", apply : "_applyBorderRadius" }, /** bottom left corner radius */ radiusBottomLeft : { nullable : true, check : "Integer", apply : "_applyBorderRadius" }, /** bottom right corner radius */ radiusBottomRight : { nullable : true, check : "Integer", apply : "_applyBorderRadius" }, /** Property group to set the corner radius of all sides */ radius : { group : [ "radiusTopLeft", "radiusTopRight", "radiusBottomRight", "radiusBottomLeft" ], mode : "shorthand" } }, members : { /** * Takes a styles map and adds the border radius styles in place to the * given map. This is the needed behavior for * {@link qx.ui.decoration.DynamicDecorator}. * * @param styles {Map} A map to add the styles. */ _styleBorderRadius : function(styles) { // Fixing the background bleed in Webkits // http://tumble.sneak.co.nz/post/928998513/fixing-the-background-bleed styles["-webkit-background-clip"] = "padding-box"; // radius handling var radius = this.getRadiusTopLeft(); if (radius > 0) { styles["-moz-border-radius-topleft"] = radius + "px"; styles["-webkit-border-top-left-radius"] = radius + "px"; styles["border-top-left-radius"] = radius + "px"; } radius = this.getRadiusTopRight(); if (radius > 0) { styles["-moz-border-radius-topright"] = radius + "px"; styles["-webkit-border-top-right-radius"] = radius + "px"; styles["border-top-right-radius"] = radius + "px"; } radius = this.getRadiusBottomLeft(); if (radius > 0) { styles["-moz-border-radius-bottomleft"] = radius + "px"; styles["-webkit-border-bottom-left-radius"] = radius + "px"; styles["border-bottom-left-radius"] = radius + "px"; } radius = this.getRadiusBottomRight(); if (radius > 0) { styles["-moz-border-radius-bottomright"] = radius + "px"; styles["-webkit-border-bottom-right-radius"] = radius + "px"; styles["border-bottom-right-radius"] = radius + "px"; } }, // property apply _applyBorderRadius : function() { if (qx.core.Environment.get("qx.debug")) { if (this._isInitialized()) { throw new Error("This decorator is already in-use. Modification is not possible anymore!"); } } } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2010 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Mixin responsible for setting the background color of a widget. * This mixin is usually used by {@link qx.ui.decoration.DynamicDecorator}. */ qx.Mixin.define("qx.ui.decoration.MBackgroundColor", { properties : { /** Color of the background */ backgroundColor : { check : "Color", nullable : true, apply : "_applyBackgroundColor" } }, members : { /** * Tint function for the background color. This is suitable for the * {@link qx.ui.decoration.DynamicDecorator}. * * @param element {Element} The element which could be resized. * @param bgcolor {Color} The new background color. * @param styles {Map} A map of styles to apply. */ _tintBackgroundColor : function(element, bgcolor, styles) { if (bgcolor == null) { bgcolor = this.getBackgroundColor(); } if (qx.core.Environment.get("qx.theme")) { bgcolor = qx.theme.manager.Color.getInstance().resolve(bgcolor); } styles.backgroundColor = bgcolor || ""; }, /** * Resize function for the background color. This is suitable for the * {@link qx.ui.decoration.DynamicDecorator}. * * @param element {Element} The element which could be resized. * @param width {Number} The new width. * @param height {Number} The new height. * @return {Map} A map containing the desired position and dimension * (width, height, top, left). */ _resizeBackgroundColor : function(element, width, height) { var insets = this.getInsets(); width -= insets.left + insets.right; height -= insets.top + insets.bottom; return { left : insets.left, top : insets.top, width : width, height : height }; }, // property apply _applyBackgroundColor : function() { if (qx.core.Environment.get("qx.debug")) { if (this._isInitialized()) { throw new Error("This decorator is already in-use. Modification is not possible anymore!"); } } } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2009 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Mixin for supporting the background images on decorators. * This mixin is usually used by {@link qx.ui.decoration.DynamicDecorator}. */ qx.Mixin.define("qx.ui.decoration.MBackgroundImage", { properties : { /** The URL of the background image */ backgroundImage : { check : "String", nullable : true, apply : "_applyBackgroundImage" }, /** How the background image should be repeated */ backgroundRepeat : { check : ["repeat", "repeat-x", "repeat-y", "no-repeat", "scale"], init : "repeat", apply : "_applyBackgroundImage" }, /** * Either a string or a number, which defines the horizontal position * of the background image. * * If the value is an integer it is interpreted as a pixel value, otherwise * the value is taken to be a CSS value. For CSS, the values are "center", * "left" and "right". */ backgroundPositionX : { nullable : true, apply : "_applyBackgroundImage" }, /** * Either a string or a number, which defines the vertical position * of the background image. * * If the value is an integer it is interpreted as a pixel value, otherwise * the value is taken to be a CSS value. For CSS, the values are "top", * "center" and "bottom". */ backgroundPositionY : { nullable : true, apply : "_applyBackgroundImage" }, /** * Property group to define the background position */ backgroundPosition : { group : ["backgroundPositionY", "backgroundPositionX"] } }, members : { /** * Mapping for the dynamic decorator. */ _generateMarkup : this._generateBackgroundMarkup, /** * Responsible for generating the markup for the background. * This method just uses the settings in the properties to generate * the markup. * * @param styles {Map} CSS styles as map * @param content {String?null} The content of the created div as HTML * @return {String} The generated HTML fragment */ _generateBackgroundMarkup: function(styles, content) { var markup = ""; var image = this.getBackgroundImage(); var repeat = this.getBackgroundRepeat(); var top = this.getBackgroundPositionY(); if (top == null) { top = 0; } var left = this.getBackgroundPositionX(); if (left == null) { left = 0; } styles.backgroundPosition = left + " " + top; // Support for images if (image) { var resolved = qx.util.AliasManager.getInstance().resolve(image); markup = qx.bom.element.Decoration.create(resolved, repeat, styles); } else { if ((qx.core.Environment.get("engine.name") == "mshtml")) { /* * Internet Explorer as of version 6 for quirks and standards mode, * or version 7 in quirks mode adds an empty string to the "div" * node. This behavior causes rendering problems, because the node * would then have a minimum size determined by the font size. * To be able to set the "div" node height to a certain (small) * value independent of the minimum font size, an "overflow:hidden" * style is added. * */ if (parseFloat(qx.core.Environment.get("engine.version")) < 7 || qx.core.Environment.get("browser.quirksmode")) { // Add additionally style styles.overflow = "hidden"; } } if (!content) { content = ""; } markup = '<div style="' + qx.bom.element.Style.compile(styles) + '">' + content + '</div>'; } return markup; }, // property apply _applyBackgroundImage : function() { if (qx.core.Environment.get("qx.debug")) { if (this._isInitialized()) { throw new Error("This decorator is already in-use. Modification is not possible anymore!"); } } } } });/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2010 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * A basic decorator featuring simple borders based on CSS styles. * This mixin is usually used by {@link qx.ui.decoration.DynamicDecorator}. */ qx.Mixin.define("qx.ui.decoration.MSingleBorder", { properties : { /* --------------------------------------------------------------------------- PROPERTY: WIDTH --------------------------------------------------------------------------- */ /** top width of border */ widthTop : { check : "Number", init : 0, apply : "_applyWidth" }, /** right width of border */ widthRight : { check : "Number", init : 0, apply : "_applyWidth" }, /** bottom width of border */ widthBottom : { check : "Number", init : 0, apply : "_applyWidth" }, /** left width of border */ widthLeft : { check : "Number", init : 0, apply : "_applyWidth" }, /* --------------------------------------------------------------------------- PROPERTY: STYLE --------------------------------------------------------------------------- */ /** top style of border */ styleTop : { nullable : true, check : [ "solid", "dotted", "dashed", "double"], init : "solid", apply : "_applyStyle" }, /** right style of border */ styleRight : { nullable : true, check : [ "solid", "dotted", "dashed", "double"], init : "solid", apply : "_applyStyle" }, /** bottom style of border */ styleBottom : { nullable : true, check : [ "solid", "dotted", "dashed", "double"], init : "solid", apply : "_applyStyle" }, /** left style of border */ styleLeft : { nullable : true, check : [ "solid", "dotted", "dashed", "double"], init : "solid", apply : "_applyStyle" }, /* --------------------------------------------------------------------------- PROPERTY: COLOR --------------------------------------------------------------------------- */ /** top color of border */ colorTop : { nullable : true, check : "Color", apply : "_applyStyle" }, /** right color of border */ colorRight : { nullable : true, check : "Color", apply : "_applyStyle" }, /** bottom color of border */ colorBottom : { nullable : true, check : "Color", apply : "_applyStyle" }, /** left color of border */ colorLeft : { nullable : true, check : "Color", apply : "_applyStyle" }, /* --------------------------------------------------------------------------- PROPERTY GROUP: EDGE --------------------------------------------------------------------------- */ /** Property group to configure the left border */ left : { group : [ "widthLeft", "styleLeft", "colorLeft" ] }, /** Property group to configure the right border */ right : { group : [ "widthRight", "styleRight", "colorRight" ] }, /** Property group to configure the top border */ top : { group : [ "widthTop", "styleTop", "colorTop" ] }, /** Property group to configure the bottom border */ bottom : { group : [ "widthBottom", "styleBottom", "colorBottom" ] }, /* --------------------------------------------------------------------------- PROPERTY GROUP: TYPE --------------------------------------------------------------------------- */ /** Property group to set the border width of all sides */ width : { group : [ "widthTop", "widthRight", "widthBottom", "widthLeft" ], mode : "shorthand" }, /** Property group to set the border style of all sides */ style : { group : [ "styleTop", "styleRight", "styleBottom", "styleLeft" ], mode : "shorthand" }, /** Property group to set the border color of all sides */ color : { group : [ "colorTop", "colorRight", "colorBottom", "colorLeft" ], mode : "shorthand" } }, members : { /** * Takes a styles map and adds the border styles styles in place * to the given map. This is the needed behavior for * {@link qx.ui.decoration.DynamicDecorator}. * * @param styles {Map} A map to add the styles. */ _styleBorder : function(styles) { if (qx.core.Environment.get("qx.theme")) { var Color = qx.theme.manager.Color.getInstance(); var colorTop = Color.resolve(this.getColorTop()); var colorRight = Color.resolve(this.getColorRight()); var colorBottom = Color.resolve(this.getColorBottom()); var colorLeft = Color.resolve(this.getColorLeft()); } else { var colorTop = this.getColorTop(); var colorRight = this.getColorRight(); var colorBottom = this.getColorBottom(); var colorLeft = this.getColorLeft(); } // Add borders var width = this.getWidthTop(); if (width > 0) { styles["border-top"] = width + "px " + this.getStyleTop() + " " + (colorTop || ""); } var width = this.getWidthRight(); if (width > 0) { styles["border-right"] = width + "px " + this.getStyleRight() + " " + (colorRight || ""); } var width = this.getWidthBottom(); if (width > 0) { styles["border-bottom"] = width + "px " + this.getStyleBottom() + " " + (colorBottom || ""); } var width = this.getWidthLeft(); if (width > 0) { styles["border-left"] = width + "px " + this.getStyleLeft() + " " + (colorLeft || ""); } // Check if valid if (qx.core.Environment.get("qx.debug")) { if (styles.length === 0) { throw new Error("Invalid Single decorator (zero border width). Use qx.ui.decorator.Background instead!"); } } // Add basic styles styles.position = "absolute"; styles.top = 0; styles.left = 0; }, /** * Resize function for the decorator. This is suitable for the * {@link qx.ui.decoration.DynamicDecorator}. * * @param element {Element} The element which could be resized. * @param width {Number} The new width. * @param height {Number} The new height. * @return {Map} A map containing the desired position and dimension. * (width, height, top, left). */ _resizeBorder : function(element, width, height) { var insets = this.getInsets(); width -= insets.left + insets.right; height -= insets.top + insets.bottom; // Fix to keep applied size above zero // Makes issues in IE7 when applying value like '-4px' if (width < 0) { width = 0; } if (height < 0) { height = 0; } return { left : insets.left - this.getWidthLeft(), top : insets.top - this.getWidthTop(), width : width, height : height }; }, /** * Implementation of the interface for the single border. * * @return {Map} A map containing the default insets. * (top, right, bottom, left) */ _getDefaultInsetsForBorder : function() { return { top : this.getWidthTop(), right : this.getWidthRight(), bottom : this.getWidthBottom(), left : this.getWidthLeft() }; }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyWidth : function() { this._applyStyle(); this._resetInsets(); }, // property apply _applyStyle : function() { if (qx.core.Environment.get("qx.debug")) { if (this._markup) { throw new Error("This decorator is already in-use. Modification is not possible anymore!"); } } } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A basic decorator featuring background colors and simple borders based on * CSS styles. */ qx.Class.define("qx.ui.decoration.Single", { extend : qx.ui.decoration.Abstract, include : [ qx.ui.decoration.MBackgroundImage, qx.ui.decoration.MBackgroundColor, qx.ui.decoration.MSingleBorder ], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param width {Integer} Width of the border * @param style {String} Any supported border style * @param color {Color} The border color */ construct : function(width, style, color) { this.base(arguments); // Initialize properties if (width != null) { this.setWidth(width); } if (style != null) { this.setStyle(style); } if (color != null) { this.setColor(color); } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { _markup : null, /* --------------------------------------------------------------------------- INTERFACE IMPLEMENTATION --------------------------------------------------------------------------- */ // interface implementation getMarkup : function() { if (this._markup) { return this._markup; } var styles = {}; // get the single border styles this._styleBorder(styles); var html = this._generateBackgroundMarkup(styles); return this._markup = html; }, // interface implementation resize : function(element, width, height) { // get the width and height of the mixins var pos = this._resizeBorder(element, width, height); element.style.width = pos.width + "px"; element.style.height = pos.height + "px"; element.style.left = pos.left + "px"; element.style.top = pos.top + "px"; }, // interface implementation tint : function(element, bgcolor) { this._tintBackgroundColor(element, bgcolor, element.style); }, // overridden _isInitialized: function() { return !!this._markup; }, // overridden _getDefaultInsets : function() { return this._getDefaultInsetsForBorder(); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this._markup = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A very simple decorator featuring background images and colors. No * border is supported. */ qx.Class.define("qx.ui.decoration.Background", { extend : qx.ui.decoration.Abstract, include : [ qx.ui.decoration.MBackgroundImage, qx.ui.decoration.MBackgroundColor ], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param backgroundColor {Color} Initialize with background color */ construct : function(backgroundColor) { this.base(arguments); if (backgroundColor != null) { this.setBackgroundColor(backgroundColor); } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __markup : null, // overridden _getDefaultInsets : function() { return { top : 0, right : 0, bottom : 0, left : 0 }; }, // overridden _isInitialized: function() { return !!this.__markup; }, /* --------------------------------------------------------------------------- INTERFACE IMPLEMENTATION --------------------------------------------------------------------------- */ // interface implementation getMarkup : function() { if (this.__markup) { return this.__markup; } var styles = { position: "absolute", top: 0, left: 0 }; var html = this._generateBackgroundMarkup(styles); // Store return this.__markup = html; }, // interface implementation resize : function(element, width, height) { var insets = this.getInsets(); element.style.width = (width - insets.left - insets.right) + "px"; element.style.height = (height - insets.top - insets.bottom) + "px"; element.style.left = -insets.left + "px"; element.style.top = -insets.top + "px"; }, // interface implementation tint : function(element, bgcolor) { this._tintBackgroundColor(element, bgcolor, element.style); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this.__markup = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * A simple decorator featuring background images and colors and a simple * uniform border based on CSS styles. */ qx.Class.define("qx.ui.decoration.Uniform", { extend : qx.ui.decoration.Single, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param width {Integer} Width of the border * @param style {String} Any supported border style * @param color {Color} The border color */ construct : function(width, style, color) { this.base(arguments); // Initialize properties if (width != null) { this.setWidth(width); } if (style != null) { this.setStyle(style); } if (color != null) { this.setColor(color); } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * Beveled is a variant of a rounded decorator which is quite optimal * regarding performance and still delivers a good set of features: * * * One pixel rounded border * * Inner glow color with optional transparency * * Repeated or scaled background image */ qx.Class.define("qx.ui.decoration.Beveled", { extend : qx.ui.decoration.Abstract, include : [qx.ui.decoration.MBackgroundImage, qx.ui.decoration.MBackgroundColor], /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param outerColor {Color} The outer border color * @param innerColor {Color} The inner border color * @param innerOpacity {Float} Opacity of inner border */ construct : function(outerColor, innerColor, innerOpacity) { this.base(arguments); // Initialize properties if (outerColor != null) { this.setOuterColor(outerColor); } if (innerColor != null) { this.setInnerColor(innerColor); } if (innerOpacity != null) { this.setInnerOpacity(innerOpacity); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /** * The color of the inner frame. */ innerColor : { check : "Color", nullable : true, apply : "_applyStyle" }, /** * The opacity of the inner frame. As this inner frame * is rendered above the background image this may be * intersting to configure as semi-transparent e.g. <code>0.4</code>. */ innerOpacity : { check : "Number", init : 1, apply : "_applyStyle" }, /** * Color of the outer frame. The corners are automatically * rendered with a slight opacity to fade into the background */ outerColor : { check : "Color", nullable : true, apply : "_applyStyle" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members : { __markup : null, // overridden _getDefaultInsets : function() { return { top : 2, right : 2, bottom : 2, left : 2 }; }, // overridden _isInitialized: function() { return !!this.__markup; }, /* --------------------------------------------------------------------------- PROPERTY APPLY ROUTINES --------------------------------------------------------------------------- */ // property apply _applyStyle : function() { if (qx.core.Environment.get("qx.debug")) { if (this.__markup) { throw new Error("This decorator is already in-use. Modification is not possible anymore!"); } } }, /* --------------------------------------------------------------------------- INTERFACE IMPLEMENTATION --------------------------------------------------------------------------- */ // interface implementation getMarkup : function() { if (this.__markup) { return this.__markup; } var Color = qx.theme.manager.Color.getInstance(); var html = []; // Prepare border styles var outerStyle = "1px solid " + Color.resolve(this.getOuterColor()) + ";"; var innerStyle = "1px solid " + Color.resolve(this.getInnerColor()) + ";"; // Outer frame html.push('<div style="overflow:hidden;font-size:0;line-height:0;">'); // Background frame html.push('<div style="'); html.push('border:', outerStyle); html.push(qx.bom.element.Opacity.compile(0.35)); html.push('"></div>'); // Horizontal frame html.push('<div style="position:absolute;top:1px;left:0px;'); html.push('border-left:', outerStyle); html.push('border-right:', outerStyle); html.push(qx.bom.element.Opacity.compile(1)); html.push('"></div>'); // Vertical frame html.push('<div style="'); html.push('position:absolute;top:0px;left:1px;'); html.push('border-top:', outerStyle); html.push('border-bottom:', outerStyle); html.push(qx.bom.element.Opacity.compile(1)); html.push('"></div>'); // Inner background frame var backgroundStyle = { position: "absolute", top: "1px", left: "1px", opacity: 1 }; html.push(this._generateBackgroundMarkup(backgroundStyle)); // Inner overlay frame html.push('<div style="position:absolute;top:1px;left:1px;'); html.push('border:', innerStyle); html.push(qx.bom.element.Opacity.compile(this.getInnerOpacity())); html.push('"></div>'); // Outer frame html.push('</div>'); // Store return this.__markup = html.join(""); }, // interface implementation resize : function(element, width, height) { // Fix to keep applied size above zero // Makes issues in IE7 when applying value like '-4px' if (width < 4) { width = 4; } if (height < 4) { height = 4; } // Fix box model if (qx.core.Environment.get("css.boxmodel") == "content") { var outerWidth = width - 2; var outerHeight = height - 2; var frameWidth = outerWidth; var frameHeight = outerHeight; var innerWidth = width - 4; var innerHeight = height - 4; } else { var outerWidth = width; var outerHeight = height; var frameWidth = width - 2; var frameHeight = height - 2; var innerWidth = frameWidth; var innerHeight = frameHeight; } var pixel = "px"; var backgroundFrame = element.childNodes[0].style; backgroundFrame.width = outerWidth + pixel; backgroundFrame.height = outerHeight + pixel; var horizontalFrame = element.childNodes[1].style; horizontalFrame.width = outerWidth + pixel; horizontalFrame.height = frameHeight + pixel; var verticalFrame = element.childNodes[2].style; verticalFrame.width = frameWidth + pixel; verticalFrame.height = outerHeight + pixel; var innerBackground = element.childNodes[3].style; innerBackground.width = frameWidth + pixel; innerBackground.height = frameHeight + pixel; var innerOverlay = element.childNodes[4].style; innerOverlay.width = innerWidth + pixel; innerOverlay.height = innerHeight + pixel; }, // interface implementation tint : function(element, bgcolor) { this._tintBackgroundColor(element, bgcolor, element.childNodes[3].style); } }, /* ***************************************************************************** DESTRUCTOR ***************************************************************************** */ destruct : function() { this.__markup = null; } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2010 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Mixin for the linear background gradient CSS property. * This mixin is usually used by {@link qx.ui.decoration.DynamicDecorator}. * * Keep in mind that this is not supported by all browsers: * * * Safari 4.0+ * * Chrome 4.0+ * * Firefox 3.6+ * * Opera 11.1+ * * IE 10+ * * IE 5.5+ (with limitations) * * For IE 5.5 to IE 9,this class uses the filter rules to create the gradient. This * has some limitations: The start and end position property can not be used. For * more details, see the original documentation: * http://msdn.microsoft.com/en-us/library/ms532997(v=vs.85).aspx */ qx.Mixin.define("qx.ui.decoration.MLinearBackgroundGradient", { properties : { /** Start start color of the background */ startColor : { check : "Color", nullable : true, apply : "_applyLinearBackgroundGradient" }, /** End end color of the background */ endColor : { check : "Color", nullable : true, apply : "_applyLinearBackgroundGradient" }, /** The orientation of the gradient. */ orientation : { check : ["horizontal", "vertical"], init : "vertical", apply : "_applyLinearBackgroundGradient" }, /** Position in percent where to start the color. */ startColorPosition : { check : "Number", init : 0, apply : "_applyLinearBackgroundGradient" }, /** Position in percent where to start the color. */ endColorPosition : { check : "Number", init : 100, apply : "_applyLinearBackgroundGradient" }, /** Defines if the given positions are in % or px.*/ colorPositionUnit : { check : ["px", "%"], init : "%", apply : "_applyLinearBackgroundGradient" }, /** Property group to set the start color including its start position. */ gradientStart : { group : ["startColor", "startColorPosition"], mode : "shorthand" }, /** Property group to set the end color including its end position. */ gradientEnd : { group : ["endColor", "endColorPosition"], mode : "shorthand" } }, members : { /** * Takes a styles map and adds the linear background styles in place to the * given map. This is the needed behavior for * {@link qx.ui.decoration.DynamicDecorator}. * * @param styles {Map} A map to add the styles. */ _styleLinearBackgroundGradient : function(styles) { var colors = this.__getColors(); var startColor = colors.start; var endColor = colors.end; var unit = this.getColorPositionUnit(); // new implementation for webkit is available since chrome 10 --> version if (qx.core.Environment.get("css.gradient.legacywebkit")) { // webkit uses px values if non are given unit = unit === "px" ? "" : unit; if (this.getOrientation() == "horizontal") { var startPos = this.getStartColorPosition() + unit +" 0" + unit; var endPos = this.getEndColorPosition() + unit + " 0" + unit; } else { var startPos = "0" + unit + " " + this.getStartColorPosition() + unit; var endPos = "0" + unit +" " + this.getEndColorPosition() + unit; } var color = "from(" + startColor + "),to(" + endColor + ")"; var value = "-webkit-gradient(linear," + startPos + "," + endPos + "," + color + ")"; styles["background"] = value; } else if (qx.core.Environment.get("css.gradient.filter") && !qx.core.Environment.get("css.gradient.linear")) { // make sure the overflow is hidden for border radius usage [BUG #6318] styles["overflow"] = "hidden"; // spec like syntax } else { var deg = this.getOrientation() == "horizontal" ? 0 : 270; // Bugfix for IE10 which seems to use the deg values wrong [BUG #6513] if (qx.core.Environment.get("browser.name") == "ie") { deg = deg - 90; } var start = startColor + " " + this.getStartColorPosition() + unit; var end = endColor + " " + this.getEndColorPosition() + unit; var prefixedName = qx.core.Environment.get("css.gradient.linear"); styles["background-image"] = prefixedName + "(" + deg + "deg, " + start + "," + end + ")"; } }, /** * Helper to get start and end color. * @return {Map} A map containing start and end color. */ __getColors : function() { if (qx.core.Environment.get("qx.theme")) { var Color = qx.theme.manager.Color.getInstance(); var startColor = Color.resolve(this.getStartColor()); var endColor = Color.resolve(this.getEndColor()); } else { var startColor = this.getStartColor(); var endColor = this.getEndColor(); } return {start: startColor, end: endColor}; }, /** * Helper for IE which applies the filter used for the gradient to a separate * DIV element which will be put into the decorator. This is necessary in case * the decorator has rounded corners. * @return {String} The HTML for the inner gradient DIV. */ _getContent : function() { // IE filter syntax // http://msdn.microsoft.com/en-us/library/ms532997(v=vs.85).aspx // It needs to be wrapped in a separate div bug #6318 if (qx.core.Environment.get("css.gradient.filter") && !qx.core.Environment.get("css.gradient.linear")) { var colors = this.__getColors(); var type = this.getOrientation() == "horizontal" ? 1 : 0; // convert all hex3 to hex6 var startColor = qx.util.ColorUtil.hex3StringToHex6String(colors.start); var endColor = qx.util.ColorUtil.hex3StringToHex6String(colors.end); // get rid of the starting '#' startColor = startColor.substring(1, startColor.length); endColor = endColor.substring(1, endColor.length); return "<div style=\"position: absolute; width: 100%; height: 100%; filter:progid:DXImageTransform.Microsoft.Gradient" + "(GradientType=" + type + ", " + "StartColorStr='#FF" + startColor + "', " + "EndColorStr='#FF" + endColor + "';)\"></div>"; } return ""; }, /** * Resize function for the background color. This is suitable for the * {@link qx.ui.decoration.DynamicDecorator}. * * @param element {Element} The element which could be resized. * @param width {Number} The new width. * @param height {Number} The new height. * @return {Map} A map containing the desired position and dimension * (width, height, top, left). */ _resizeLinearBackgroundGradient : function(element, width, height) { var insets = this.getInsets(); width -= insets.left + insets.right; height -= insets.top + insets.bottom; return { left : insets.left, top : insets.top, width : width, height : height }; }, // property apply _applyLinearBackgroundGradient : function() { if (qx.core.Environment.get("qx.debug")) { if (this._isInitialized()) { throw new Error("This decorator is already in-use. Modification is not possible anymore!"); } } } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2010 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Border implementation with two CSS borders. Both borders can be styled * independent of each other. * This mixin is usually used by {@link qx.ui.decoration.DynamicDecorator}. */ qx.Mixin.define("qx.ui.decoration.MDoubleBorder", { include : [qx.ui.decoration.MSingleBorder, qx.ui.decoration.MBackgroundImage], construct : function() { // override the methods of single border and background image this._getDefaultInsetsForBorder = this.__getDefaultInsetsForDoubleBorder; this._resizeBorder = this.__resizeDoubleBorder; this._styleBorder = this.__styleDoubleBorder; this._generateMarkup = this.__generateMarkupDoubleBorder; }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties : { /* --------------------------------------------------------------------------- PROPERTY: INNER WIDTH --------------------------------------------------------------------------- */ /** top width of border */ innerWidthTop : { check : "Number", init : 0 }, /** right width of border */ innerWidthRight : { check : "Number", init : 0 }, /** bottom width of border */ innerWidthBottom : { check : "Number", init : 0 }, /** left width of border */ innerWidthLeft : { check : "Number", init : 0 }, /** Property group to set the inner border width of all sides */ innerWidth : { group : [ "innerWidthTop", "innerWidthRight", "innerWidthBottom", "innerWidthLeft" ], mode : "shorthand" }, /* --------------------------------------------------------------------------- PROPERTY: INNER COLOR --------------------------------------------------------------------------- */ /** top inner color of border */ innerColorTop : { nullable : true, check : "Color" }, /** right inner color of border */ innerColorRight : { nullable : true, check : "Color" }, /** bottom inner color of border */ innerColorBottom : { nullable : true, check : "Color" }, /** left inner color of border */ innerColorLeft : { nullable : true, check : "Color" }, /** * Property group for the inner color properties. */ innerColor : { group : [ "innerColorTop", "innerColorRight", "innerColorBottom", "innerColorLeft" ], mode : "shorthand" } }, members : { __ownMarkup : null, /** * Takes a styles map and adds the inner border styles styles in place * to the given map. This is the needed behavior for * {@link qx.ui.decoration.DynamicDecorator}. * * @param styles {Map} A map to add the styles. */ __styleDoubleBorder : function(styles) { if (qx.core.Environment.get("qx.theme")) { var Color = qx.theme.manager.Color.getInstance(); var innerColorTop = Color.resolve(this.getInnerColorTop()); var innerColorRight = Color.resolve(this.getInnerColorRight()); var innerColorBottom = Color.resolve(this.getInnerColorBottom()); var innerColorLeft = Color.resolve(this.getInnerColorLeft()); } else { var innerColorTop = this.getInnerColorTop(); var innerColorRight = this.getInnerColorRight(); var innerColorBottom = this.getInnerColorBottom(); var innerColorLeft = this.getInnerColorLeft(); } // Inner styles // Inner image must be relative to be compatible with qooxdoo 0.8.x // See http://bugzilla.qooxdoo.org/show_bug.cgi?id=3450 for details styles.position = "relative"; // Add inner borders var width = this.getInnerWidthTop(); if (width > 0) { styles["border-top"] = width + "px " + this.getStyleTop() + " " + innerColorTop; } var width = this.getInnerWidthRight(); if (width > 0) { styles["border-right"] = width + "px " + this.getStyleRight() + " " + innerColorRight; } var width = this.getInnerWidthBottom(); if (width > 0) { styles["border-bottom"] = width + "px " + this.getStyleBottom() + " " + innerColorBottom; } var width = this.getInnerWidthLeft(); if (width > 0) { styles["border-left"] = width + "px " + this.getStyleLeft() + " " + innerColorLeft; } if (qx.core.Environment.get("qx.debug")) { if (!styles["border-top"] && !styles["border-right"] && !styles["border-bottom"] && !styles["border-left"]) { throw new Error("Invalid Double decorator (zero inner border width). Use qx.ui.decoration.Single instead!"); } } }, /** * Special generator for the markup which creates the containing div and * the sourrounding div as well. * * @param styles {Map} The styles for the inner * @return {String} The generated decorator HTML. */ __generateMarkupDoubleBorder : function(styles) { var innerHtml = this._generateBackgroundMarkup( styles, this._getContent ? this._getContent() : "" ); if (qx.core.Environment.get("qx.theme")) { var Color = qx.theme.manager.Color.getInstance(); var colorTop = Color.resolve(this.getColorTop()); var colorRight = Color.resolve(this.getColorRight()); var colorBottom = Color.resolve(this.getColorBottom()); var colorLeft = Color.resolve(this.getColorLeft()); } else { var colorTop = this.getColorTop(); var colorRight = this.getColorRight(); var colorBottom = this.getColorBottom(); var colorLeft = this.getColorLeft(); } // get rid of the old borders styles["border-top"] = ''; styles["border-right"] = ''; styles["border-bottom"] = ''; styles["border-left"] = ''; // Generate outer HTML styles["line-height"] = 0; // Do not set the line-height on IE6, IE7, IE8 in Quirks Mode and IE8 in IE7 Standard Mode // See http://bugzilla.qooxdoo.org/show_bug.cgi?id=3450 for details if ( (qx.core.Environment.get("engine.name") == "mshtml" && parseFloat(qx.core.Environment.get("engine.version")) < 8) || (qx.core.Environment.get("engine.name") == "mshtml" && qx.core.Environment.get("browser.documentmode") < 8) ) { styles["line-height"] = ''; } var width = this.getWidthTop(); if (width > 0) { styles["border-top"] = width + "px " + this.getStyleTop() + " " + colorTop; } var width = this.getWidthRight(); if (width > 0) { styles["border-right"] = width + "px " + this.getStyleRight() + " " + colorRight; } var width = this.getWidthBottom(); if (width > 0) { styles["border-bottom"] = width + "px " + this.getStyleBottom() + " " + colorBottom; } var width = this.getWidthLeft(); if (width > 0) { styles["border-left"] = width + "px " + this.getStyleLeft() + " " + colorLeft; } if (qx.core.Environment.get("qx.debug")) { if (styles["border-top"] == '' && styles["border-right"] == '' && styles["border-bottom"] == '' && styles["border-left"] == '') { throw new Error("Invalid Double decorator (zero outer border width). Use qx.ui.decoration.Single instead!"); } } // final default styles styles["position"] = "absolute"; styles["top"] = 0; styles["left"] = 0; // Store return this.__ownMarkup = this._generateBackgroundMarkup(styles, innerHtml); }, /** * Resize function for the decorator. This is suitable for the * {@link qx.ui.decoration.DynamicDecorator}. * * @param element {Element} The element which could be resized. * @param width {Number} The new width. * @param height {Number} The new height. * @return {Map} A map containing the desired position and dimension and a * emelent to resize. * (width, height, top, left, elementToApplyDimensions). */ __resizeDoubleBorder : function(element, width, height) { var insets = this.getInsets(); width -= insets.left + insets.right; height -= insets.top + insets.bottom; var left = insets.left - this.getWidthLeft() - this.getInnerWidthLeft(); var top = insets.top - this.getWidthTop() - this.getInnerWidthTop(); return { left: left, top: top, width: width, height: height, elementToApplyDimensions : element.firstChild }; }, /** * Implementation of the interface for the double border. * * @return {Map} A map containing the default insets. * (top, right, bottom, left) */ __getDefaultInsetsForDoubleBorder : function() { return { top : this.getWidthTop() + this.getInnerWidthTop(), right : this.getWidthRight() + this.getInnerWidthRight(), bottom : this.getWidthBottom() + this.getInnerWidthBottom(), left : this.getWidthLeft() + this.getInnerWidthLeft() }; } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2010 1&1 Internet AG, Germany, http://www.1und1.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * Mixin for the box shadow CSS property. * This mixin is usually used by {@link qx.ui.decoration.DynamicDecorator}. * * Keep in mind that this is not supported by all browsers: * * * Firefox 3,5+ * * IE9+ * * Safari 3.0+ * * Opera 10.5+ * * Chrome 4.0+ */ qx.Mixin.define("qx.ui.decoration.MBoxShadow", { properties : { /** Horizontal length of the shadow. */ shadowHorizontalLength : { nullable : true, check : "Integer", apply : "_applyBoxShadow" }, /** Vertical length of the shadow. */ shadowVerticalLength : { nullable : true, check : "Integer", apply : "_applyBoxShadow" }, /** The blur radius of the shadow. */ shadowBlurRadius : { nullable : true, check : "Integer", apply : "_applyBoxShadow" }, /** The spread radius of the shadow. */ shadowSpreadRadius : { nullable : true, check : "Integer", apply : "_applyBoxShadow" }, /** The color of the shadow. */ shadowColor : { nullable : true, check : "Color", apply : "_applyBoxShadow" }, /** Inset shadows are drawn inside the border. */ inset : { init : false, check : "Boolean", apply : "_applyBoxShadow" }, /** Property group to set the shadow length. */ shadowLength : { group : ["shadowHorizontalLength", "shadowVerticalLength"], mode : "shorthand" } }, members : { /** * Takes a styles map and adds the box shadow styles in place to the * given map. This is the needed behavior for * {@link qx.ui.decoration.DynamicDecorator}. * * @param styles {Map} A map to add the styles. */ _styleBoxShadow : function(styles) { if (qx.core.Environment.get("qx.theme")) { var Color = qx.theme.manager.Color.getInstance(); var color = Color.resolve(this.getShadowColor()); } else { var color = this.getShadowColor(); } if (color != null) { var vLength = this.getShadowVerticalLength() || 0; var hLength = this.getShadowHorizontalLength() || 0; var blur = this.getShadowBlurRadius() || 0; var spread = this.getShadowSpreadRadius() || 0; var inset = this.getInset() ? "inset " : ""; var value = inset + hLength + "px " + vLength + "px " + blur + "px " + spread + "px " + color; styles["-moz-box-shadow"] = value; styles["-webkit-box-shadow"] = value; styles["box-shadow"] = value; } }, // property apply _applyBoxShadow : function() { if (qx.core.Environment.get("qx.debug")) { if (this._isInitialized()) { throw new Error("This decorator is already in-use. Modification is not possible anymore!"); } } } } }); /* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de 2006 STZ-IDA, Germany, http://www.stz-ida.de License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Fabian Jakobs (fjakobs) * Sebastian Werner (wpbasti) * Andreas Ecker (ecker) * Alexander Steitz (aback) * Martin Wittemann (martinwittemann) ************************************************************************* */ /* ************************************************************************ #asset(qx/decoration/Modern/*) ************************************************************************ */ /** * The modern decoration theme. */ qx.Theme.define("qx.theme.modern.Decoration", { aliases : { decoration : "qx/decoration/Modern" }, decorations : { /* --------------------------------------------------------------------------- CORE --------------------------------------------------------------------------- */ "main" : { decorator: qx.ui.decoration.Uniform, style : { width : 1, color : "border-main" } }, "selected" : { decorator : qx.ui.decoration.Background, style : { backgroundImage : "decoration/selection.png", backgroundRepeat : "scale" } }, "selected-css" : { decorator : [ qx.ui.decoration.MLinearBackgroundGradient ], style : { startColorPosition : 0, endColorPosition : 100, startColor : "selected-start", endColor : "selected-end" } }, "selected-dragover" : { decorator : qx.ui.decoration.Single, style : { backgroundImage : "decoration/selection.png", backgroundRepeat : "scale", bottom: [2, "solid", "border-dragover"] } }, "dragover" : { decorator : qx.ui.decoration.Single, style : { bottom: [2, "solid", "border-dragover"] } }, "pane" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/pane/pane.png", insets : [0, 2, 3, 0] } }, "pane-css" : { decorator : [ qx.ui.decoration.MSingleBorder, qx.ui.decoration.MBorderRadius, qx.ui.decoration.MBoxShadow, qx.ui.decoration.MLinearBackgroundGradient ], style : { width: 1, color: "tabview-background", radius : 3, shadowColor : "shadow", shadowBlurRadius : 2, shadowLength : 0, gradientStart : ["pane-start", 0], gradientEnd : ["pane-end", 100] } }, "group" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/groupbox/groupbox.png" } }, "group-css" : { decorator : [ qx.ui.decoration.MBackgroundColor, qx.ui.decoration.MBorderRadius, qx.ui.decoration.MSingleBorder ], style : { backgroundColor : "group-background", radius : 4, color : "group-border", width: 1 } }, "border-invalid" : { decorator : qx.ui.decoration.Beveled, style : { outerColor : "invalid", innerColor : "border-inner-input", innerOpacity : 0.5, backgroundImage : "decoration/form/input.png", backgroundRepeat : "repeat-x", backgroundColor : "background-light" } }, "keyboard-focus" : { decorator : qx.ui.decoration.Single, style : { width : 1, color : "keyboard-focus", style : "dotted" } }, /* --------------------------------------------------------------------------- CSS RADIO BUTTON --------------------------------------------------------------------------- */ "radiobutton" : { decorator : [ qx.ui.decoration.MDoubleBorder, qx.ui.decoration.MBackgroundColor, qx.ui.decoration.MBorderRadius, qx.ui.decoration.MBoxShadow ], style : { backgroundColor : "radiobutton-background", radius : 5, width: 1, innerWidth : 2, color : "checkbox-border", innerColor : "radiobutton-background", shadowLength : 0, shadowBlurRadius : 0, shadowColor : "checkbox-focus", insetLeft: 5 // used for the shadow (3 border + 2 extra for the shadow) } }, "radiobutton-checked" : { include : "radiobutton", style : { backgroundColor : "radiobutton-checked" } }, "radiobutton-checked-focused" : { include : "radiobutton-checked", style : { shadowBlurRadius : 4 } }, "radiobutton-checked-hovered" : { include : "radiobutton-checked", style : { innerColor : "checkbox-hovered" } }, "radiobutton-focused" : { include : "radiobutton", style : { shadowBlurRadius : 4 } }, "radiobutton-hovered" : { include : "radiobutton", style : { backgroundColor : "checkbox-hovered", innerColor : "checkbox-hovered" } }, "radiobutton-disabled" : { include : "radiobutton", style : { innerColor : "radiobutton-disabled", backgroundColor : "radiobutton-disabled", color : "checkbox-disabled-border" } }, "radiobutton-checked-disabled" : { include : "radiobutton-disabled", style : { backgroundColor : "radiobutton-checked-disabled" } }, "radiobutton-invalid" : { include : "radiobutton", style : { color : "invalid" } }, "radiobutton-checked-invalid" : { include : "radiobutton-checked", style : { color : "invalid" } }, "radiobutton-checked-focused-invalid" : { include : "radiobutton-checked-focused", style : { color : "invalid", shadowColor : "invalid" } }, "radiobutton-checked-hovered-invalid" : { include : "radiobutton-checked-hovered", style : { color : "invalid", innerColor : "radiobutton-hovered-invalid" } }, "radiobutton-focused-invalid" : { include : "radiobutton-focused", style : { color : "invalid", shadowColor : "invalid" } }, "radiobutton-hovered-invalid" : { include : "radiobutton-hovered", style : { color : "invalid", innerColor : "radiobutton-hovered-invalid", backgroundColor : "radiobutton-hovered-invalid" } }, /* --------------------------------------------------------------------------- SEPARATOR --------------------------------------------------------------------------- */ "separator-horizontal" : { decorator: qx.ui.decoration.Single, style : { widthLeft : 1, colorLeft : "border-separator" } }, "separator-vertical" : { decorator: qx.ui.decoration.Single, style : { widthTop : 1, colorTop : "border-separator" } }, /* --------------------------------------------------------------------------- TOOLTIP --------------------------------------------------------------------------- */ "tooltip-error" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/form/tooltip-error.png", insets : [ 2, 5, 5, 2 ] } }, "tooltip-error-css" : { decorator : [ qx.ui.decoration.MBackgroundColor, qx.ui.decoration.MBorderRadius, qx.ui.decoration.MBoxShadow ], style : { backgroundColor : "tooltip-error", radius : 4, shadowColor : "shadow", shadowBlurRadius : 2, shadowLength : 1, insets: [-2, 0, 0, -2] } }, "tooltip-error-css-left" : { include : "tooltip-error-css", style : { insets : [1, 0, 0, 2] } }, "tooltip-error-arrow" : { decorator: qx.ui.decoration.Background, style: { backgroundImage: "decoration/form/tooltip-error-arrow.png", backgroundPositionY: "top", backgroundRepeat: "no-repeat", insets: [-4, 0, 0, 13] } }, "tooltip-error-arrow-left" : { decorator: qx.ui.decoration.Background, style: { backgroundImage: "decoration/form/tooltip-error-arrow-right.png", backgroundPositionY: "top", backgroundPositionX: "right", backgroundRepeat: "no-repeat", insets: [-4, -13, 0, 0] } }, "tooltip-error-arrow-left-css" : { decorator: qx.ui.decoration.Background, style: { backgroundImage: "decoration/form/tooltip-error-arrow-right.png", backgroundPositionY: "top", backgroundPositionX: "right", backgroundRepeat: "no-repeat", insets: [-6, -13, 0, 0] } }, /* --------------------------------------------------------------------------- SHADOWS --------------------------------------------------------------------------- */ "shadow-window" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/shadow/shadow.png", insets : [ 4, 8, 8, 4 ] } }, "shadow-window-css" : { decorator : [ qx.ui.decoration.MBoxShadow, qx.ui.decoration.MBackgroundColor ], style : { shadowColor : "shadow", shadowBlurRadius : 2, shadowLength : 1 } }, "shadow-popup" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/shadow/shadow-small.png", insets : [ 0, 3, 3, 0 ] } }, "popup-css" : { decorator: [ qx.ui.decoration.MSingleBorder, qx.ui.decoration.MBoxShadow, qx.ui.decoration.MBackgroundColor ], style : { width : 1, color : "border-main", shadowColor : "shadow", shadowBlurRadius : 3, shadowLength : 1 } }, /* --------------------------------------------------------------------------- SCROLLBAR --------------------------------------------------------------------------- */ "scrollbar-horizontal" : { decorator : qx.ui.decoration.Background, style : { backgroundImage : "decoration/scrollbar/scrollbar-bg-horizontal.png", backgroundRepeat : "repeat-x" } }, "scrollbar-vertical" : { decorator : qx.ui.decoration.Background, style : { backgroundImage : "decoration/scrollbar/scrollbar-bg-vertical.png", backgroundRepeat : "repeat-y" } }, "scrollbar-slider-horizontal" : { decorator : qx.ui.decoration.Beveled, style : { backgroundImage : "decoration/scrollbar/scrollbar-button-bg-horizontal.png", backgroundRepeat : "scale", outerColor : "border-main", innerColor : "border-inner-scrollbar", innerOpacity : 0.5 } }, "scrollbar-slider-horizontal-disabled" : { decorator : qx.ui.decoration.Beveled, style : { backgroundImage : "decoration/scrollbar/scrollbar-button-bg-horizontal.png", backgroundRepeat : "scale", outerColor : "border-disabled", innerColor : "border-inner-scrollbar", innerOpacity : 0.3 } }, "scrollbar-slider-vertical" : { decorator : qx.ui.decoration.Beveled, style : { backgroundImage : "decoration/scrollbar/scrollbar-button-bg-vertical.png", backgroundRepeat : "scale", outerColor : "border-main", innerColor : "border-inner-scrollbar", innerOpacity : 0.5 } }, "scrollbar-slider-vertical-disabled" : { decorator : qx.ui.decoration.Beveled, style : { backgroundImage : "decoration/scrollbar/scrollbar-button-bg-vertical.png", backgroundRepeat : "scale", outerColor : "border-disabled", innerColor : "border-inner-scrollbar", innerOpacity : 0.3 } }, // PLAIN CSS SCROLLBAR "scrollbar-horizontal-css" : { decorator : [qx.ui.decoration.MLinearBackgroundGradient], style : { gradientStart : ["scrollbar-start", 0], gradientEnd : ["scrollbar-end", 100] } }, "scrollbar-vertical-css" : { include : "scrollbar-horizontal-css", style : { orientation : "horizontal" } }, "scrollbar-slider-horizontal-css" : { decorator : [ qx.ui.decoration.MSingleBorder, qx.ui.decoration.MLinearBackgroundGradient ], style : { gradientStart : ["scrollbar-slider-start", 0], gradientEnd : ["scrollbar-slider-end", 100], color : "border-main", width: 1 } }, "scrollbar-slider-vertical-css" : { include : "scrollbar-slider-horizontal-css", style : { orientation : "horizontal" } }, "scrollbar-slider-horizontal-disabled-css" : { include : "scrollbar-slider-horizontal-css", style : { color : "button-border-disabled" } }, "scrollbar-slider-vertical-disabled-css" : { include : "scrollbar-slider-vertical-css", style : { color : "button-border-disabled" } }, /* --------------------------------------------------------------------------- PLAIN CSS BUTTON --------------------------------------------------------------------------- */ "button-css" : { decorator : [ qx.ui.decoration.MSingleBorder, qx.ui.decoration.MLinearBackgroundGradient, qx.ui.decoration.MBorderRadius ], style : { radius: 3, color: "border-button", width: 1, startColor: "button-start", endColor: "button-end", startColorPosition: 35, endColorPosition: 100 } }, "button-disabled-css" : { include : "button-css", style : { color : "button-border-disabled", startColor: "button-disabled-start", endColor: "button-disabled-end" } }, "button-hovered-css" : { include : "button-css", style : { startColor : "button-hovered-start", endColor : "button-hovered-end" } }, "button-checked-css" : { include : "button-css", style : { endColor: "button-start", startColor: "button-end" } }, "button-pressed-css" : { include : "button-css", style : { endColor : "button-hovered-start", startColor : "button-hovered-end" } }, "button-focused-css" : { decorator : [ qx.ui.decoration.MDoubleBorder, qx.ui.decoration.MLinearBackgroundGradient, qx.ui.decoration.MBorderRadius ], style : { radius: 3, color: "border-button", width: 1, innerColor: "button-focused", innerWidth: 2, startColor: "button-start", endColor: "button-end", startColorPosition: 30, endColorPosition: 100 } }, "button-checked-focused-css" : { include : "button-focused-css", style : { endColor: "button-start", startColor: "button-end" } }, // invalid "button-invalid-css" : { include : "button-css", style : { color: "border-invalid" } }, "button-disabled-invalid-css" : { include : "button-disabled-css", style : { color : "border-invalid" } }, "button-hovered-invalid-css" : { include : "button-hovered-css", style : { color : "border-invalid" } }, "button-checked-invalid-css" : { include : "button-checked-css", style : { color : "border-invalid" } }, "button-pressed-invalid-css" : { include : "button-pressed-css", style : { color : "border-invalid" } }, "button-focused-invalid-css" : { include : "button-focused-css", style : { color : "border-invalid" } }, "button-checked-focused-invalid-css" : { include : "button-checked-focused-css", style : { color : "border-invalid" } }, /* --------------------------------------------------------------------------- BUTTON --------------------------------------------------------------------------- */ "button" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/form/button.png", insets : 2 } }, "button-disabled" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/form/button-disabled.png", insets : 2 } }, "button-focused" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/form/button-focused.png", insets : 2 } }, "button-hovered" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/form/button-hovered.png", insets : 2 } }, "button-pressed" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/form/button-pressed.png", insets : 2 } }, "button-checked" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/form/button-checked.png", insets : 2 } }, "button-checked-focused" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/form/button-checked-focused.png", insets : 2 } }, "button-invalid-shadow" : { decorator : qx.ui.decoration.Single, style : { color : "invalid", width : 1 } }, /* --------------------------------------------------------------------------- CHECKBOX --------------------------------------------------------------------------- */ "checkbox-invalid-shadow" : { decorator : qx.ui.decoration.Beveled, style : { outerColor : "invalid", innerColor : "border-focused-invalid", insets: [0] } }, /* --------------------------------------------------------------------------- PLAIN CSS CHECK BOX --------------------------------------------------------------------------- */ "checkbox" : { decorator : [ qx.ui.decoration.MDoubleBorder, qx.ui.decoration.MLinearBackgroundGradient, qx.ui.decoration.MBoxShadow ], style : { width: 1, color: "checkbox-border", innerWidth : 1, innerColor : "checkbox-inner", gradientStart : ["checkbox-start", 0], gradientEnd : ["checkbox-end", 100], shadowLength : 0, shadowBlurRadius : 0, shadowColor : "checkbox-focus", insetLeft: 4 // (2 for the border and two for the glow effect) } }, "checkbox-hovered" : { include : "checkbox", style : { innerColor : "checkbox-hovered-inner", // use the same color to get a single colored background gradientStart : ["checkbox-hovered", 0], gradientEnd : ["checkbox-hovered", 100] } }, "checkbox-focused" : { include : "checkbox", style : { shadowBlurRadius : 4 } }, "checkbox-disabled" : { include : "checkbox", style : { color : "checkbox-disabled-border", innerColor : "checkbox-disabled-inner", gradientStart : ["checkbox-disabled-start", 0], gradientEnd : ["checkbox-disabled-end", 100] } }, "checkbox-invalid" : { include : "checkbox", style : { color : "invalid" } }, "checkbox-hovered-invalid" : { include : "checkbox-hovered", style : { color : "invalid", innerColor : "checkbox-hovered-inner-invalid", gradientStart : ["checkbox-hovered-invalid", 0], gradientEnd : ["checkbox-hovered-invalid", 100] } }, "checkbox-focused-invalid" : { include : "checkbox-focused", style : { color : "invalid", shadowColor : "invalid" } }, /* --------------------------------------------------------------------------- PLAIN CSS TEXT FIELD --------------------------------------------------------------------------- */ "input-css" : { decorator : [ qx.ui.decoration.MDoubleBorder, qx.ui.decoration.MLinearBackgroundGradient, qx.ui.decoration.MBackgroundColor ], style : { color : "border-input", innerColor : "border-inner-input", innerWidth: 1, width : 1, backgroundColor : "background-light", startColor : "input-start", endColor : "input-end", startColorPosition : 0, endColorPosition : 12, colorPositionUnit : "px" } }, "border-invalid-css" : { include : "input-css", style : { color : "border-invalid" } }, "input-focused-css" : { include : "input-css", style : { startColor : "input-focused-start", innerColor : "input-focused-end", endColorPosition : 4 } }, "input-focused-invalid-css" : { include : "input-focused-css", style : { innerColor : "input-focused-inner-invalid", color : "border-invalid" } }, "input-disabled-css" : { include : "input-css", style : { color: "input-border-disabled" } }, /* --------------------------------------------------------------------------- TEXT FIELD --------------------------------------------------------------------------- */ "input" : { decorator : qx.ui.decoration.Beveled, style : { outerColor : "border-input", innerColor : "border-inner-input", innerOpacity : 0.5, backgroundImage : "decoration/form/input.png", backgroundRepeat : "repeat-x", backgroundColor : "background-light" } }, "input-focused" : { decorator : qx.ui.decoration.Beveled, style : { outerColor : "border-input", innerColor : "border-focused", backgroundImage : "decoration/form/input-focused.png", backgroundRepeat : "repeat-x", backgroundColor : "background-light" } }, "input-focused-invalid" : { decorator : qx.ui.decoration.Beveled, style : { outerColor : "invalid", innerColor : "border-focused-invalid", backgroundImage : "decoration/form/input-focused.png", backgroundRepeat : "repeat-x", backgroundColor : "background-light", insets: [2] } }, "input-disabled" : { decorator : qx.ui.decoration.Beveled, style : { outerColor : "border-disabled", innerColor : "border-inner-input", innerOpacity : 0.5, backgroundImage : "decoration/form/input.png", backgroundRepeat : "repeat-x", backgroundColor : "background-light" } }, /* --------------------------------------------------------------------------- TOOLBAR --------------------------------------------------------------------------- */ "toolbar" : { decorator : qx.ui.decoration.Background, style : { backgroundImage : "decoration/toolbar/toolbar-gradient.png", backgroundRepeat : "scale" } }, "toolbar-css" : { decorator : [qx.ui.decoration.MLinearBackgroundGradient], style : { startColorPosition : 40, endColorPosition : 60, startColor : "toolbar-start", endColor : "toolbar-end" } }, "toolbar-button-hovered" : { decorator : qx.ui.decoration.Beveled, style : { outerColor : "border-toolbar-button-outer", innerColor : "border-toolbar-border-inner", backgroundImage : "decoration/form/button-c.png", backgroundRepeat : "scale" } }, "toolbar-button-checked" : { decorator : qx.ui.decoration.Beveled, style : { outerColor : "border-toolbar-button-outer", innerColor : "border-toolbar-border-inner", backgroundImage : "decoration/form/button-checked-c.png", backgroundRepeat : "scale" } }, "toolbar-button-hovered-css" : { decorator : [ qx.ui.decoration.MDoubleBorder, qx.ui.decoration.MLinearBackgroundGradient, qx.ui.decoration.MBorderRadius ], style : { color : "border-toolbar-button-outer", width: 1, innerWidth: 1, innerColor : "border-toolbar-border-inner", radius : 2, gradientStart : ["button-start", 30], gradientEnd : ["button-end", 100] } }, "toolbar-button-checked-css" : { include : "toolbar-button-hovered-css", style : { gradientStart : ["button-end", 30], gradientEnd : ["button-start", 100] } }, "toolbar-separator" : { decorator : qx.ui.decoration.Single, style : { widthLeft : 1, widthRight : 1, colorLeft : "border-toolbar-separator-left", colorRight : "border-toolbar-separator-right", styleLeft : "solid", styleRight : "solid" } }, "toolbar-part" : { decorator : qx.ui.decoration.Background, style : { backgroundImage : "decoration/toolbar/toolbar-part.gif", backgroundRepeat : "repeat-y" } }, /* --------------------------------------------------------------------------- TABVIEW --------------------------------------------------------------------------- */ "tabview-pane" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/tabview/tabview-pane.png", insets : [ 4, 6, 7, 4 ] } }, "tabview-pane-css" : { decorator : [ qx.ui.decoration.MBorderRadius, qx.ui.decoration.MLinearBackgroundGradient, qx.ui.decoration.MSingleBorder ], style : { width: 1, color: "window-border", radius : 3, gradientStart : ["tabview-start", 90], gradientEnd : ["tabview-end", 100] } }, "tabview-page-button-top-active" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/tabview/tab-button-top-active.png" } }, "tabview-page-button-top-inactive" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/tabview/tab-button-top-inactive.png" } }, "tabview-page-button-bottom-active" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/tabview/tab-button-bottom-active.png" } }, "tabview-page-button-bottom-inactive" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/tabview/tab-button-bottom-inactive.png" } }, "tabview-page-button-left-active" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/tabview/tab-button-left-active.png" } }, "tabview-page-button-left-inactive" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/tabview/tab-button-left-inactive.png" } }, "tabview-page-button-right-active" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/tabview/tab-button-right-active.png" } }, "tabview-page-button-right-inactive" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/tabview/tab-button-right-inactive.png" } }, // CSS TABVIEW BUTTONS "tabview-page-button-top-active-css" : { decorator : [ qx.ui.decoration.MBorderRadius, qx.ui.decoration.MSingleBorder, qx.ui.decoration.MBackgroundColor, qx.ui.decoration.MBoxShadow ], style : { radius : [3, 3, 0, 0], width: [1, 1, 0, 1], color: "tabview-background", backgroundColor : "tabview-start", shadowLength: 1, shadowColor: "shadow", shadowBlurRadius: 2 } }, "tabview-page-button-top-inactive-css" : { decorator : [ qx.ui.decoration.MBorderRadius, qx.ui.decoration.MSingleBorder, qx.ui.decoration.MLinearBackgroundGradient ], style : { radius : [3, 3, 0, 0], color: "tabview-inactive", colorBottom : "tabview-background", width: 1, gradientStart : ["tabview-inactive-start", 0], gradientEnd : ["tabview-inactive-end", 100] } }, "tabview-page-button-bottom-active-css" : { include : "tabview-page-button-top-active-css", style : { radius : [0, 0, 3, 3], width: [0, 1, 1, 1], backgroundColor : "tabview-inactive-start" } }, "tabview-page-button-bottom-inactive-css" : { include : "tabview-page-button-top-inactive-css", style : { radius : [0, 0, 3, 3], width: [0, 1, 1, 1], colorBottom : "tabview-inactive", colorTop : "tabview-background" } }, "tabview-page-button-left-active-css" : { include : "tabview-page-button-top-active-css", style : { radius : [3, 0, 0, 3], width: [1, 0, 1, 1], shadowLength: 0, shadowBlurRadius: 0 } }, "tabview-page-button-left-inactive-css" : { include : "tabview-page-button-top-inactive-css", style : { radius : [3, 0, 0, 3], width: [1, 0, 1, 1], colorBottom : "tabview-inactive", colorRight : "tabview-background" } }, "tabview-page-button-right-active-css" : { include : "tabview-page-button-top-active-css", style : { radius : [0, 3, 3, 0], width: [1, 1, 1, 0], shadowLength: 0, shadowBlurRadius: 0 } }, "tabview-page-button-right-inactive-css" : { include : "tabview-page-button-top-inactive-css", style : { radius : [0, 3, 3, 0], width: [1, 1, 1, 0], colorBottom : "tabview-inactive", colorLeft : "tabview-background" } }, /* --------------------------------------------------------------------------- SPLITPANE --------------------------------------------------------------------------- */ "splitpane" : { decorator : qx.ui.decoration.Uniform, style : { backgroundColor : "background-pane", width : 3, color : "background-splitpane", style : "solid" } }, /* --------------------------------------------------------------------------- WINDOW --------------------------------------------------------------------------- */ "window" : { decorator: qx.ui.decoration.Single, style : { backgroundColor : "background-pane", width : 1, color : "border-main", widthTop : 0 } }, "window-captionbar-active" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/window/captionbar-active.png" } }, "window-captionbar-inactive" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/window/captionbar-inactive.png" } }, "window-statusbar" : { decorator : qx.ui.decoration.Grid, style : { baseImage : "decoration/window/statusbar.png" } }, // CSS WINDOW "window-css" : { decorator : [ qx.ui.decoration.MBorderRadius, qx.ui.decoration.MBoxShadow, qx.ui.decoration.MSingleBorder ], style : { radius : [5, 5, 0, 0], shadowBlurRadius : 4, shadowLength : 2, shadowColor : "shadow" } }, "window-incl-statusbar-css" : { include : "window-css", style : { radius : [5, 5, 5, 5] } }, "window-resize-frame-css" : { decorator : [ qx.ui.decoration.MBorderRadius, qx.ui.decoration.MSingleBorder ], style : { radius : [5, 5, 0, 0], width : 1, color : "border-main" } }, "window-resize-frame-incl-statusbar-css" : { include : "window-resize-frame-css", style : { radius : [5, 5, 5, 5] } }, "window-captionbar-active-css" : { decorator : [ qx.ui.decoration.MSingleBorder, qx.ui.decoration.MBorderRadius, qx.ui.decoration.MLinearBackgroundGradient ], style : { width : 1, color : "window-border", colorBottom : "window-border-caption", radius : [5, 5, 0, 0], gradientStart : ["window-caption-active-start", 30], gradientEnd : ["window-caption-active-end", 70] } }, "window-captionbar-inactive-css" : { include : "window-captionbar-active-css", style : { gradientStart : ["window-caption-inactive-start", 30], gradientEnd : ["window-caption-inactive-end", 70] } }, "window-statusbar-css" : { decorator : [ qx.ui.decoration.MBackgroundColor, qx.ui.decoration.MSingleBorder, qx.ui.decoration.MBorderRadius ], style : { backgroundColor : "window-statusbar-background", width: [0, 1, 1, 1], color: "window-border", radius : [0, 0, 5, 5] } }, "window-pane-css" : { decorator: [ qx.ui.decoration.MSingleBorder, qx.ui.decoration.MBackgroundColor ], style : { backgroundColor : "background-pane", width : 1, color : "window-border", widthTop : 0 } }, /* --------------------------------------------------------------------------- TABLE --------------------------------------------------------------------------- */ "table" : { decorator : qx.ui.decoration.Single, style : { width : 1, color : "border-main", style : "solid" } }, "table-statusbar" : { decorator : qx.ui.decoration.Single, style : { widthTop : 1, colorTop : "border-main", style : "solid" } }, "table-scroller-header" : { decorator : qx.ui.decoration.Single, style : { backgroundImage : "decoration/table/header-cell.png", backgroundRepeat : "scale", widthBottom : 1, colorBottom : "border-main", style : "solid" } }, "table-scroller-header-css" : { decorator : [ qx.ui.decoration.MSingleBorder, qx.ui.decoration.MLinearBackgroundGradient ], style : { gradientStart : ["table-header-start", 10], gradientEnd : ["table-header-end", 90], widthBottom : 1, colorBottom : "border-main" } }, "table-header-cell" : { decorator : qx.ui.decoration.Single, style : { widthRight : 1, colorRight : "border-separator", styleRight : "solid" } }, "table-header-cell-hovered" : { decorator : qx.ui.decoration.Single, style : { widthRight : 1, colorRight : "border-separator", styleRight : "solid", widthBottom : 1, colorBottom : "table-header-hovered", styleBottom : "solid" } }, "table-scroller-focus-indicator" : { decorator : qx.ui.decoration.Single, style : { width : 2, color : "table-focus-indicator", style : "solid" } }, /* --------------------------------------------------------------------------- PROGRESSIVE --------------------------------------------------------------------------- */ "progressive-table-header" : { decorator : qx.ui.decoration.Single, style : { width : 1, color : "border-main", style : "solid" } }, "progressive-table-header-cell" : { decorator : qx.ui.decoration.Single, style : { backgroundImage : "decoration/table/header-cell.png", backgroundRepeat : "scale", widthRight : 1, colorRight : "progressive-table-header-border-right", style : "solid" } }, "progressive-table-header-cell-css" : { decorator : [ qx.ui.decoration.MSingleBorder, qx.ui.decoration.MLinearBackgroundGradient ], style : { gradientStart : ["table-header-start", 10], gradientEnd : ["table-header-end", 90], widthRight : 1, colorRight : "progressive-table-header-border-right" } }, /* --------------------------------------------------------------------------- MENU --------------------------------------------------------------------------- */ "menu" : { decorator : qx.ui.decoration.Single, style : { backgroundImage : "decoration/menu/background.png", backgroundRepeat : "scale", width : 1, color : "border-main", style : "solid" } }, "menu-css" : { decorator : [ qx.ui.decoration.MLinearBackgroundGradient, qx.ui.decoration.MBoxShadow, qx.ui.decoration.MSingleBorder ], style : { gradientStart : ["menu-start", 0], gradientEnd : ["menu-end", 100], shadowColor : "shadow", shadowBlurRadius : 2, shadowLength : 1, width : 1, color : "border-main" } }, "menu-separator" : { decorator : qx.ui.decoration.Single, style : { widthTop : 1, colorTop : "menu-separator-top", widthBottom : 1, colorBottom : "menu-separator-bottom" } }, /* --------------------------------------------------------------------------- MENU BAR --------------------------------------------------------------------------- */ "menubar" : { decorator : qx.ui.decoration.Single, style : { backgroundImage : "decoration/menu/bar-background.png", backgroundRepeat : "scale", width : 1, color : "border-separator", style : "solid" } }, "menubar-css" : { decorator : [ qx.ui.decoration.MSingleBorder, qx.ui.decoration.MLinearBackgroundGradient ], style : { gradientStart : ["menubar-start", 0], gradientEnd : ["menu-end", 100], width : 1, color : "border-separator" } }, /* --------------------------------------------------------------------------- APPLICATION --------------------------------------------------------------------------- */ "app-header": { decorator : qx.ui.decoration.Background, style : { backgroundImage : "decoration/app-header.png", backgroundRepeat : "scale" } }, /* --------------------------------------------------------------------------- PROGRESSBAR --------------------------------------------------------------------------- */ "progressbar" : { decorator: qx.ui.decoration.Single, style: { width: 1, color: "border-input" } }, /* --------------------------------------------------------------------------- VIRTUAL WIDGETS --------------------------------------------------------------------------- */ "group-item" : { decorator : qx.ui.decoration.Background, style : { backgroundImage : "decoration/group-item.png", backgroundRepeat : "scale" } }, "group-item-css" : { decorator : [ qx.ui.decoration.MLinearBackgroundGradient ], style : { startColorPosition : 0, endColorPosition : 100, startColor : "groupitem-start", endColor : "groupitem-end" } } } });
icarusfactor/lugDBwizard
qooxdoo_source/lugwizupdate/source/script/lugwiz.10a10b4d8340.js
JavaScript
gpl-3.0
775,345
<?php class SnapinAssociationManager extends FOGManagerController { }
wolfbane8653/fogproject
packages/web/lib/fog/SnapinAssociationManager.class.php
PHP
gpl-3.0
70
/* * Copyright (c) 2006-2016 Marvisan Pty. Ltd. All rights reserved. * Use is subject to license terms. */ /* * QuoteResponseLevel.java * * $Id: QuoteResponseLevel.java,v 1.3 2010-01-14 09:06:48 vrotaru Exp $ */ package net.hades.fix.message.type; import java.util.HashMap; import java.util.Map; import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlType; /** * Level of Response requested from receiver of quote messages. * * @author <a href="mailto:support@marvisan.com">Support Team</a> * @version $Revision: 1.3 $ * @created 21/04/2009, 9:51:34 AM */ @XmlType @XmlEnum(Integer.class) public enum QuoteResponseLevel { @XmlEnumValue("0") NoAck (0), @XmlEnumValue("1") AckOnlyNegativeOrErroneous (1), @XmlEnumValue("2") AckEachQuote (2), @XmlEnumValue("3") SummaryAck (3); private static final long serialVersionUID = -8326896911735835286L; private int value; private static final Map<String, QuoteResponseLevel> stringToEnum = new HashMap<String, QuoteResponseLevel>(); static { for (QuoteResponseLevel tag : values()) { stringToEnum.put(String.valueOf(tag.getValue()), tag); } } /** Creates a new instance of QuoteResponseLevel */ QuoteResponseLevel(int value) { this.value = value; } public int getValue() { return value; } public static QuoteResponseLevel valueFor(int value) { return stringToEnum.get(String.valueOf(value)); } }
marvisan/HadesFIX
Model/src/main/java/net/hades/fix/message/type/QuoteResponseLevel.java
Java
gpl-3.0
1,649
(function (angular) { angular.module("rmApp", ["ui.router", "rmApp.templates", "rmApp.controllers"]) .config(["$stateProvider", "$urlRouterProvider", "$locationProvider", function ($stateProvider, $urlRouterProvider, $locationProvider) { $urlRouterProvider.otherwise("/"); $locationProvider.html5Mode(false); // $stateProvider .state("index", { url: "/", templateUrl: "index.tpl.html", controller: "rmCtrl" }) .state("home", { url: "/home", templateUrl: "home.tpl.html", controller: "rmCtrl" }).state("about", { url: "/about", templateUrl: "about.tpl.html", controller: "rmCtrl" }).state("contact", { url: "/contact", templateUrl: "contact.tpl.html", controller: "rmCtrl" }).state("spinner1", { url: "/spinner1", templateUrl: "spinner1.tpl.html", controller: "rmCtrl" }).state("spinner2", { url: "/spinner2", templateUrl: "spinner2.tpl.html", controller: "rmCtrl" }); }]); })(angular);
rawlinsmethod/ProAngularJS
app/www/js/routers/index.rtr.js
JavaScript
gpl-3.0
1,378
package hu.smiths.dvdcomposer.model.algorithm; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.Set; import hu.smiths.dvdcomposer.model.Disc; import hu.smiths.dvdcomposer.model.exceptions.CannotFindValidAssignmentException; import hu.smiths.dvdcomposer.model.exceptions.CannotLoadAlgorithmClass; public class OuterAlgorithm implements Algorithm { private Algorithm algorithm; private OuterAlgorithm(Algorithm algorithm) { this.algorithm = algorithm; } public static OuterAlgorithm createFromJarAndClassFQN(File jar, String classFQN) throws CannotLoadAlgorithmClass { return new OuterAlgorithm(load(jar, classFQN)); } private static Algorithm load(File jar, String classFQN) throws CannotLoadAlgorithmClass { try { Class<?> loadedClass = getClassFromJar(jar, classFQN); return getNewAlgorithmInstance(loadedClass); } catch (IOException | IllegalArgumentException | SecurityException | IllegalAccessException | ClassNotFoundException | InstantiationException e) { throw new CannotLoadAlgorithmClass("Cannot load " + classFQN + " from " + jar.getAbsolutePath(), e); } } private static Class<?> getClassFromJar(File jar, String classFQN) throws MalformedURLException, ClassNotFoundException { URL url = jar.toURI().toURL(); URLClassLoader loader = new URLClassLoader(new URL[] { url }, OuterAlgorithm.class.getClassLoader()); return Class.forName(classFQN, true, loader); } private static Algorithm getNewAlgorithmInstance(Class<?> clazz) throws CannotLoadAlgorithmClass, InstantiationException, IllegalAccessException { if (Algorithm.class.isAssignableFrom(clazz)) { return (Algorithm) clazz.newInstance(); } else { throw new CannotLoadAlgorithmClass( clazz.toGenericString() + " doesn't implements " + Algorithm.class.toGenericString() + "!"); } } @Override public Set<Disc> generate(Input input) throws CannotFindValidAssignmentException { try { return algorithm.generate(input); } catch (Throwable t) { throw new CannotFindValidAssignmentException("The outer algorithm could not find a valid assigment!", t); } } public void changeAlgorithm(File jar, String classFQN) throws CannotLoadAlgorithmClass{ algorithm = load(jar, classFQN); } }
antaljanosbenjamin/DVDComposer
src/main/java/hu/smiths/dvdcomposer/model/algorithm/OuterAlgorithm.java
Java
gpl-3.0
2,346
/* * Copyright (C) 2020 GeorgH93 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package at.pcgamingfreaks.Message; import com.google.gson.annotations.SerializedName; import org.jetbrains.annotations.NotNull; import lombok.Getter; import lombok.Setter; /** * The click event is used for the JSON messages when the part of the message using it is clicked. */ public class MessageClickEvent { /** * The action that should be executed when the click event is triggered. */ @Getter @Setter private @NotNull ClickEventAction action; /** * The value to be used when the click action is triggered. */ @Getter @Setter private @NotNull String value; /** * Creates a new click event for a JSON message component. * * @param action The action that should be executed on click. * @param value The value used for the action of the event. */ public MessageClickEvent(final @NotNull ClickEventAction action, final @NotNull String value) { this.action = action; this.value = value; } /** * Enum with all possible actions for a click event. */ public enum ClickEventAction { /** * Runs a command as the clicking player. */ @SerializedName("run_command") RUN_COMMAND, /** * Suggests a command in the chat bar of the clicking player. */ @SerializedName("suggest_command") SUGGEST_COMMAND, /** * Opens a url in the browser of the clicking player. */ @SerializedName("open_url") OPEN_URL, /** * Changes the page of the book the clicking player is currently reading. <b>Only works in books!!!</b> */ @SerializedName("change_page") CHANGE_PAGE, /** * Opens a file on the clicking players hard drive. Used from minecraft for the clickable screenshot link. * The chance that we know the path to a file on the clients hard disk is pretty low, so the usage of this is pretty limited. */ @SerializedName("open_file") OPEN_FILE } }
GeorgH93/Bukkit_Bungee_PluginLib
pcgf_pluginlib-common/src/at/pcgamingfreaks/Message/MessageClickEvent.java
Java
gpl-3.0
2,531
<?php session_start(); if($_SESSION['mat_sistema'] == ""){die;} require_once "familia.class.php"; $FamiliaProd = new FamiliaProd; echo $FamiliaProd->gravar( array('nome' => $_POST['nome'] ) ); ?>
Brasmid/servicedesk-metal
modules/grava_categoria_produto.php
PHP
gpl-3.0
198
////////////////////////////////////////////////////////////////////////// // This file is part of openPSTD. // // // // openPSTD is free software: you can redistribute it and/or modify // // it under the terms of the GNU General Public License as published by // // the Free Software Foundation, either version 3 of the License, or // // (at your option) any later version. // // // // openPSTD is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with openPSTD. If not, see <http://www.gnu.org/licenses/>. // // // ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // // Date: 1-11-2015 // // // Authors: M. R. Fortuin // // // Purpose: Test cases for de Edge class // // ////////////////////////////////////////////////////////////////////////// #ifdef STAND_ALONE # define BOOST_TEST_MODULE Main #endif #include <boost/test/unit_test.hpp> #include <GUI/Edges.h> using namespace OpenPSTD::GUI; BOOST_AUTO_TEST_SUITE(GUI) BOOST_AUTO_TEST_SUITE(GUI_Edges) BOOST_AUTO_TEST_CASE(TestHorizontal) { BOOST_CHECK(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false).IsHorizontal()); BOOST_CHECK(!Edge(QVector2D(10, 0), QVector2D(10, 10), 0, false).IsHorizontal()); } BOOST_AUTO_TEST_CASE(TestVertical) { BOOST_CHECK(Edge(QVector2D(10, 0), QVector2D(10, 10), 0, false).IsVertical()); BOOST_CHECK(!Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false).IsVertical()); } BOOST_AUTO_TEST_CASE(TestGetStart) { BOOST_CHECK(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false).GetStart() == QVector2D(0, 10)); } BOOST_AUTO_TEST_CASE(TestGetEnd) { BOOST_CHECK(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false).GetEnd() == QVector2D(10, 10)); } BOOST_AUTO_TEST_CASE(TestOnSameLine) { BOOST_CHECK(Edge::OnSameLine(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false), Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false))); BOOST_CHECK(!Edge::OnSameLine(Edge(QVector2D(0, 11), QVector2D(10, 11), 0, false), Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false))); BOOST_CHECK(!Edge::OnSameLine(Edge(QVector2D(10, 0), QVector2D(10, 10), 0, false), Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false))); BOOST_CHECK(Edge::OnSameLine(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false), Edge(QVector2D(10, 10), QVector2D(20, 10), 0, false))); BOOST_CHECK(!Edge::OnSameLine(Edge(QVector2D(0, 0), QVector2D(10, 10), 0, false), Edge(QVector2D(10, 10), QVector2D(20, 10), 0, false))); } BOOST_AUTO_TEST_CASE(TestSubstract) { BOOST_CHECK(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false).Substract(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false)).empty()); BOOST_CHECK(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false).Substract(Edge(QVector2D(0, 10), QVector2D(5, 10), 0, false))[0].GetStart() == QVector2D(5, 10)); BOOST_CHECK(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false).Substract(Edge(QVector2D(0, 10), QVector2D(5, 10), 0, false))[0].GetEnd() == QVector2D(10, 10)); BOOST_CHECK(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false).Substract(Edge(QVector2D(5, 10), QVector2D(10, 10), 0, false))[0].GetStart() == QVector2D(0, 10)); BOOST_CHECK(Edge(QVector2D(0, 10), QVector2D(10, 10), 0, false).Substract(Edge(QVector2D(5, 10), QVector2D(10, 10), 0, false))[0].GetEnd() == QVector2D(5, 10)); } BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
openPSTD/openPSTD
test/GUI/Edges-test.cpp
C++
gpl-3.0
4,237
/** * */ var $info = false; function LoadServerStats() { $.getJSON("phpsysinfo/xml.php?plugin=complete&json", function (data) { $info = data; updateCPU($info.Vitals["@attributes"].LoadAvg, $info.Vitals["@attributes"].Processes); updateRAM($info.Memory["@attributes"].Percent); updateHDD($info.FileSystem.Mount[0]["@attributes"].Percent); /** OTHER INFO **/ updateIP($info.Network.NetDevice); updateUptime($info.Vitals["@attributes"].Uptime); updateUSB($info.Hardware.USB.Device); }); setTimeout(LoadServerStats, 10000); } function updateUSB(devices) { var $html = ""; $.each(devices, function (i, val) { $html += '<div class="row"><span class="value">' + val['@attributes'].Name + '</span></div>'; }); $('.other-info-stats .usb-devices .usb-list').html($html); } function updateUptime(value) { var d = new Date(0, 0, 0, 0, 0, value); var s = d.getSeconds(); var m = d.getMinutes(); var h = d.getHours(); var D = d.getDate(); var M = d.getMonth(); var Y = d.getYear(); var formated = ''; if (Y > 0) formated += ' ' + Y + 'Y' if (M > 0) formated += ' ' + M + 'M' if (D > 0) formated += ' ' + D + 'D' if (h > 0) formated += ' ' + h + 'h' if (m > 0) formated += ' ' + m + 'm' if (s > 0) formated += ' ' + s + 's' $('.other-info-stats .uptime span.value').html(formated); } function updateIP(value) { var ipadd = "" if ($.isArray(value)) { $.each(value, function (i, val) { var list = val['@attributes'].Info; var arr = list.split(';'); ipadd += ' ' + arr[1]; }); } else { var list = value['@attributes'].Info; var arr = list.split(';'); ipadd += ' ' + arr[1]; } $('.other-info-stats .ip-address span.value').html(ipadd); } function updateHDD(value) { $('.usage .disk .progress-bar').css('width', value + '%'); $('.usage .disk .progress-bar span.value').html(value + '%'); } function updateRAM(value) { $('.ram.chart').data('easyPieChart').update(Math.round(value)); } function updateCPU(loadavg, processesCount) { var data = loadavg; var arr = data.split(' '); var $value = (arr[0] / processesCount) * 100; $('.cpu.chart').data('easyPieChart').update(Math.round($value)); }
volrathxiii/Avy
js/serverstats.js
JavaScript
gpl-3.0
2,489
///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2021- Equinor ASA // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RicExecuteLastUsedScriptFeature.h" #include "RiaApplication.h" #include "RicExecuteScriptFeature.h" #include "RimCalcScript.h" #include "RimProject.h" #include "RimScriptCollection.h" #include "cafCmdFeatureManager.h" #include <QAction> #include <QFileInfo> #include <QSettings> CAF_CMD_SOURCE_INIT( RicExecuteLastUsedScriptFeature, "RicExecuteLastUsedScriptFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QString RicExecuteLastUsedScriptFeature::lastUsedScriptPathKey() { return "lastUsedScriptPath"; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicExecuteLastUsedScriptFeature::isCommandEnabled() { return true; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicExecuteLastUsedScriptFeature::onActionTriggered( bool isChecked ) { QSettings settings; QString lastUsedScript = settings.value( lastUsedScriptPathKey() ).toString(); if ( !lastUsedScript.isEmpty() ) { RimScriptCollection* rootScriptCollection = RiaApplication::instance()->project()->scriptCollection(); std::vector<RimCalcScript*> scripts; rootScriptCollection->descendantsIncludingThisOfType( scripts ); for ( auto c : scripts ) { if ( c->absoluteFileName() == lastUsedScript ) { RicExecuteScriptFeature::executeScript( c ); return; } } } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicExecuteLastUsedScriptFeature::setupActionLook( QAction* actionToSetup ) { QString actionText = "Execute Last Used Script"; QSettings settings; QString lastUsedScript = settings.value( lastUsedScriptPathKey() ).toString(); if ( !lastUsedScript.isEmpty() ) { QFileInfo fi( lastUsedScript ); QString fileName = fi.fileName(); if ( !fileName.isEmpty() ) { actionText = "Execute " + fileName; } } actionToSetup->setText( actionText ); }
OPM/ResInsight
ApplicationLibCode/Commands/OctaveScriptCommands/RicExecuteLastUsedScriptFeature.cpp
C++
gpl-3.0
3,371
# -*- encoding: utf-8 -*- """Generic base class for cli hammer commands.""" import logging from robottelo import ssh from robottelo.cli import hammer from robottelo.config import conf class CLIError(Exception): """Indicates that a CLI command could not be run.""" class CLIReturnCodeError(Exception): """Indicates that a CLI command has finished with return code, different from zero. :param return_code: CLI command return code :param stderr: contents of the ``stderr`` :param msg: explanation of the error """ def __init__(self, return_code, stderr, msg): self.return_code = return_code self.stderr = stderr self.msg = msg def __str__(self): return self.msg class Base(object): """ @param command_base: base command of hammer. Output of recent `hammer --help`:: activation-key Manipulate activation keys. architecture Manipulate architectures. auth Foreman connection login/logout. auth-source Manipulate auth sources. capsule Manipulate capsule compute-resource Manipulate compute resources. content-host Manipulate content hosts on the server content-view Manipulate content views. docker-image Manipulate docker images domain Manipulate domains. environment Manipulate environments. erratum Manipulate errata fact Search facts. filter Manage permission filters. global-parameter Manipulate global parameters. gpg Manipulate GPG Key actions on the server host Manipulate hosts. host-collection Manipulate host collections hostgroup Manipulate hostgroups. import Import data exported from a Red Hat Sat.. lifecycle-environment Manipulate lifecycle_environments location Manipulate locations. medium Manipulate installation media. model Manipulate hardware models. organization Manipulate organizations os Manipulate operating system. package Manipulate packages. package-group Manipulate package groups partition-table Manipulate partition tables. ping Get the status of the server product Manipulate products. proxy Manipulate smart proxies. puppet-class Search puppet modules. puppet-module View Puppet Module details. report Browse and read reports. repository Manipulate repositories repository-set Manipulate repository sets on the server role Manage user roles. sc-param Manipulate smart class parameters. shell Interactive shell subnet Manipulate subnets. subscription Manipulate subscriptions. sync-plan Manipulate sync plans task Tasks related actions. template Manipulate config templates. user Manipulate users. user-group Manage user groups. @since: 27.Nov.2013 """ command_base = None # each inherited instance should define this command_sub = None # specific to instance, like: create, update, etc command_requires_org = False # True when command requires organization-id logger = logging.getLogger('robottelo') @classmethod def _handle_response(cls, response, ignore_stderr=None): """Verify ``return_code`` of the CLI command. Check for a non-zero return code or any stderr contents. :param response: a ``SSHCommandResult`` object, returned by :mod:`robottelo.ssh.command`. :param ignore_stderr: indicates whether to throw a warning in logs if ``stderr`` is not empty. :returns: contents of ``stdout``. :raises robottelo.cli.base.CLIReturnCodeError: If return code is different from zero. """ if response.return_code != 0: raise CLIReturnCodeError( response.return_code, response.stderr, u'Command "{0} {1}" finished with return_code {2}\n' 'stderr contains following message:\n{3}' .format( cls.command_base, cls.command_sub, response.return_code, response.stderr, ) ) if len(response.stderr) != 0 and not ignore_stderr: cls.logger.warning( u'stderr contains following message:\n{0}' .format(response.stderr) ) return response.stdout @classmethod def add_operating_system(cls, options=None): """ Adds OS to record. """ cls.command_sub = 'add-operatingsystem' result = cls.execute(cls._construct_command(options)) return result @classmethod def create(cls, options=None): """ Creates a new record using the arguments passed via dictionary. """ cls.command_sub = 'create' if options is None: options = {} result = cls.execute( cls._construct_command(options), output_format='csv') # Extract new object ID if it was successfully created if len(result) > 0 and 'id' in result[0]: obj_id = result[0]['id'] # Fetch new object # Some Katello obj require the organization-id for subcommands info_options = {u'id': obj_id} if cls.command_requires_org: if 'organization-id' not in options: raise CLIError( 'organization-id option is required for {0}.create' .format(cls.__name__) ) info_options[u'organization-id'] = options[u'organization-id'] new_obj = cls.info(info_options) # stdout should be a dictionary containing the object if len(new_obj) > 0: result = new_obj return result @classmethod def delete(cls, options=None): """Deletes existing record.""" cls.command_sub = 'delete' return cls.execute( cls._construct_command(options), ignore_stderr=True, ) @classmethod def delete_parameter(cls, options=None): """ Deletes parameter from record. """ cls.command_sub = 'delete-parameter' result = cls.execute(cls._construct_command(options)) return result @classmethod def dump(cls, options=None): """ Displays the content for existing partition table. """ cls.command_sub = 'dump' result = cls.execute(cls._construct_command(options)) return result @classmethod def _get_username_password(cls, username=None, password=None): """Lookup for the username and password for cli command in following order: 1. ``user`` or ``password`` parameters 2. ``foreman_admin_username`` or ``foreman_admin_password`` attributes 3. foreman.admin.username or foreman.admin.password configuration :return: A tuple with the username and password found :rtype: tuple """ if username is None: try: username = getattr(cls, 'foreman_admin_username') except AttributeError: username = conf.properties['foreman.admin.username'] if password is None: try: password = getattr(cls, 'foreman_admin_password') except AttributeError: password = conf.properties['foreman.admin.password'] return (username, password) @classmethod def execute(cls, command, user=None, password=None, output_format=None, timeout=None, ignore_stderr=None, return_raw_response=None): """Executes the cli ``command`` on the server via ssh""" user, password = cls._get_username_password(user, password) # add time to measure hammer performance perf_test = conf.properties.get('performance.test.foreman.perf', '0') cmd = u'LANG={0} {1} hammer -v -u {2} -p {3} {4} {5}'.format( conf.properties['main.locale'], u'time -p' if perf_test == '1' else '', user, password, u'--output={0}'.format(output_format) if output_format else u'', command, ) response = ssh.command( cmd.encode('utf-8'), output_format=output_format, timeout=timeout, ) if return_raw_response: return response else: return cls._handle_response( response, ignore_stderr=ignore_stderr, ) @classmethod def exists(cls, options=None, search=None): """Search for an entity using the query ``search[0]="search[1]"`` Will be used the ``list`` command with the ``--search`` option to do the search. If ``options`` argument already have a search key, then the ``search`` argument will not be evaluated. Which allows different search query. """ if options is None: options = {} if search is not None and u'search' not in options: options.update({u'search': u'{0}=\\"{1}\\"'.format( search[0], search[1])}) result = cls.list(options) if result: result = result[0] return result @classmethod def info(cls, options=None, output_format=None): """Reads the entity information.""" cls.command_sub = 'info' if options is None: options = {} if cls.command_requires_org and 'organization-id' not in options: raise CLIError( 'organization-id option is required for {0}.info' .format(cls.__name__) ) result = cls.execute( command=cls._construct_command(options), output_format=output_format ) if output_format != 'json': result = hammer.parse_info(result) return result @classmethod def list(cls, options=None, per_page=True): """ List information. @param options: ID (sometimes name works as well) to retrieve info. """ cls.command_sub = 'list' if options is None: options = {} if 'per-page' not in options and per_page: options[u'per-page'] = 10000 if cls.command_requires_org and 'organization-id' not in options: raise CLIError( 'organization-id option is required for {0}.list' .format(cls.__name__) ) result = cls.execute( cls._construct_command(options), output_format='csv') return result @classmethod def puppetclasses(cls, options=None): """ Lists all puppet classes. """ cls.command_sub = 'puppet-classes' result = cls.execute( cls._construct_command(options), output_format='csv') return result @classmethod def remove_operating_system(cls, options=None): """ Removes OS from record. """ cls.command_sub = 'remove-operatingsystem' result = cls.execute(cls._construct_command(options)) return result @classmethod def sc_params(cls, options=None): """ Lists all smart class parameters. """ cls.command_sub = 'sc-params' result = cls.execute( cls._construct_command(options), output_format='csv') return result @classmethod def set_parameter(cls, options=None): """ Creates or updates parameter for a record. """ cls.command_sub = 'set-parameter' result = cls.execute(cls._construct_command(options)) return result @classmethod def update(cls, options=None): """ Updates existing record. """ cls.command_sub = 'update' result = cls.execute( cls._construct_command(options), output_format='csv') return result @classmethod def with_user(cls, username=None, password=None): """Context Manager for credentials""" if username is None: username = conf.properties['foreman.admin.username'] if password is None: password = conf.properties['foreman.admin.password'] class Wrapper(cls): """Wrapper class which defines the foreman admin username and password to be used when executing any cli command. """ foreman_admin_username = username foreman_admin_password = password return Wrapper @classmethod def _construct_command(cls, options=None): """ Build a hammer cli command based on the options passed """ tail = u'' if options is None: options = {} for key, val in options.items(): if val is None: continue if val is True: tail += u' --{0}'.format(key) elif val is not False: if isinstance(val, list): val = ','.join(str(el) for el in val) tail += u' --{0}="{1}"'.format(key, val) cmd = u'{0} {1} {2}'.format( cls.command_base, cls.command_sub, tail.strip() ) return cmd
abalakh/robottelo
robottelo/cli/base.py
Python
gpl-3.0
14,527
normIncludes = [ {"fieldName": "field1", "includes": "GOOD,VALUE", "excludes": "BAD,STUFF", "begins": "", "ends": "", "replace": "goodvalue"}, {"fieldName": "field1", "includes": "", "excludes": "", "begins": "ABC", "ends": "", "replace": "goodvalue"}, {"fieldName": "field1", "includes": "", "excludes": "", "begins": "", "ends": "XYZ", "replace": "goodvalue"}, {"fieldName": "field100"} ]
rh-marketingops/dwm
dwm/test/test_normIncludes.py
Python
gpl-3.0
407
#region license /* MediaFoundationLib - Provide access to MediaFoundation interfaces via .NET Copyright (C) 2007 http://mfnet.sourceforge.net This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #endregion using System; using System.Text; using System.Runtime.InteropServices; using MediaFoundation.Misc; using System.Drawing; namespace MediaFoundation.Core.Classes { #if NOT_IN_USE /// <summary> /// Specifies a rectangular area within a video frame. /// </summary> /// <remarks> /// <code language="cpp" title="C/C++ Syntax"> /// typedef struct _MFVideoArea { /// MFOffset OffsetX; /// MFOffset OffsetY; /// SIZE     Area; /// } MFVideoArea; /// </code> /// <para/> /// The above documentation is © Microsoft Corporation. It is reproduced here /// with the sole purpose to increase usability and add IntelliSense support. /// <para/> /// View the original documentation topic online: /// <a href="http://msdn.microsoft.com/en-US/library/D22B8B9C-399B-4FCE-A173-833005B5BF03(v=VS.85,d=hv.2).aspx">http://msdn.microsoft.com/en-US/library/D22B8B9C-399B-4FCE-A173-833005B5BF03(v=VS.85,d=hv.2).aspx</a> /// </remarks> [StructLayout(LayoutKind.Sequential, Pack = 4), UnmanagedName("MFVideoArea")] internal class MFVideoArea { /// <summary> /// An <see cref="MFOffset"/> structure that contains the x-coordinate of the upper-left corner of the /// rectangle. This coordinate might have a fractional value. /// </summary> public MFOffset OffsetX; /// <summary> /// An <see cref="MFOffset"/> structure that contains the y-coordinate of the upper-left corner of the /// rectangle. This coordinate might have a fractional value. /// </summary> public MFOffset OffsetY; /// <summary> /// A <see cref="Misc.MFSize"/> structure that contains the width and height of the rectangle. /// </summary> public MFSize Area; /// <summary> /// Initializes a new instance of the <see cref="MFVideoArea"/> class. /// </summary> public MFVideoArea() { OffsetX = new MFOffset(); OffsetY = new MFOffset(); } /// <summary> /// Initializes a new instance of the <see cref="MFVideoArea"/> class. /// </summary> /// <param name="x">The x-coordinate of the upper-left corner of the rectangle.</param> /// <param name="y">The y-coordinate of the upper-left corner of the rectangle.</param> /// <param name="width">The width of the rectangle.</param> /// <param name="height">The height of the rectangle.</param> public MFVideoArea(float x, float y, int width, int height) { OffsetX = new MFOffset(x); OffsetY = new MFOffset(y); Area = new MFSize(width, height); } /// <summary> /// Fill the coordinates of the this MFVideoArea instance with the given values. /// </summary> /// <param name="x">The x-coordinate of the upper-left corner of the rectangle.</param> /// <param name="y">The y-coordinate of the upper-left corner of the rectangle.</param> /// <param name="width">The width of the rectangle.</param> /// <param name="height">The height of the rectangle.</param> public void MakeArea(float x, float y, int width, int height) { OffsetX.MakeOffset(x); OffsetY.MakeOffset(y); Area.Width = width; Area.Height = height; } } #endif }
todor-dk/SuperMFLib
src/Core/Classes/MFVideoArea.cs
C#
gpl-3.0
4,297
#ifndef __HIT_COMPILERGCC_HPP__ #define __HIT_COMPILERGCC_HPP__ #include <cstdint> #include <cstddef> typedef int8_t HIT_SINT8; typedef uint8_t HIT_UINT8; typedef int16_t HIT_SINT16; typedef uint16_t HIT_UINT16; typedef int32_t HIT_SINT32; typedef uint32_t HIT_UINT32; typedef int64_t HIT_SINT64; typedef uint64_t HIT_UINT64; #endif // __HIT_COMPILERGCC_HPP__
RedRingRico/Hit
Source/Common/Headers/CompilerGCC.hpp
C++
gpl-3.0
370
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package modules; import java.io.BufferedReader; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; import java.util.Properties; import util.PropUtil; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.InputStreamReader; import java.util.Enumeration; /** * * @author cristi */ public class MeterKamstrup extends Module { @Override public void Initialize() { pDataSet = mmManager.getSharedData(PropUtil.GetString(pAttributes, "pDataSet", sName)); // PropUtil.LoadFromFile(pAssociation, PropUtil.GetString(pAttributes, "pAssociation", "")); sPrefix = PropUtil.GetString(pAttributes, "sPrefix", ""); // lPeriod = PropUtil.GetInt(pAttributes, "lPeriod", 1000); sCmdLine = PropUtil.GetString(pAttributes, "sCmdLine", ""); sStartPath = PropUtil.GetString(pAttributes, "sStartPath", ""); iTimeOut = PropUtil.GetInt(pAttributes, "iTimeOut", 30000); iPause = PropUtil.GetInt(pAttributes, "iPause", 30000); iDebug = PropUtil.GetInt(pAttributes, "iDebug", 0); lPeriod = PropUtil.GetLong(pAttributes, "lPeriod", 5000); } // Properties pAssociation = new Properties(); // Properties pDataSet = null; String sPrefix = ""; Thread tLoop = null; Thread tWachDog = null; int iTimeOut = 30000; int iPause = 30000; long lLastRead = 0; int iDebug = 0; long lPeriod = 0; @Override public void Start() { try { sdfDate.setTimeZone(TimeZone.getDefault()); tLoop = new Thread(new Runnable() { @Override public void run() { Loop(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); tLoop.start(); if (tWachDog == null) { tWachDog = new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(1000); if (System.currentTimeMillis() - lLastRead > iTimeOut) { ReStartProc(); } } catch (Exception e) { } } } }); tWachDog.start(); } } catch (Exception e) { // Log(Name + "-Open-" + e.getMessage() + "-" + e.getCause()); } } BufferedReader br = null; String sLine = ""; String[] ssLineVars = null; String sDate = ""; String sTime = ""; private final SimpleDateFormat sdfDate = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); public void Loop() { while (bStop == 0) { try { Thread.sleep(10); try { sLine = br.readLine(); } catch (Exception ex) { ReStartProc(); continue; } if ((iDebug == 1) && (sLine!=null)) { System.out.println(sLine); } lLastRead = System.currentTimeMillis(); if ((sLine == null) || (sLine.length() < 1)) { ReStartProc(); continue; } while (sLine.contains(" ")) { sLine = sLine.replaceAll(" ", " "); } sLine = sLine.replaceAll(" ", "\t"); ssLineVars = sLine.split("\t"); if (ssLineVars.length < 2) { continue; } if ((ssLineVars[0].length() < 1) || (ssLineVars[1].length() < 1) || ("None".equals(ssLineVars[1]))) { continue; } if ("Date".equals(ssLineVars[0])) { sDate = ssLineVars[1]; if (sTime.length() > 0) { pDataSet.put(sPrefix + "Date", sDate + " " + sTime); pDataSet.put(sPrefix + "Date" + "-ts", sdfDate.format(new Date())); } } else if ("Time".equals(ssLineVars[0])) { sTime = ssLineVars[1]; } else { pDataSet.put(sPrefix + ssLineVars[0], ssLineVars[1]); pDataSet.put(sPrefix + ssLineVars[0] + "-ts", sdfDate.format(new Date())); } } catch (Exception e) { if (iDebug == 1) { System.out.println(e.getMessage()); } } } } public int Pause = 0; public int memPause = 0; public int bStop = 0; public int Debug = 0; public long lIniSysTimeMs = 0; public long lMemSysTimeMs = 0; public long ldt = 0; public double ddt = 0.0; public long lDelay = 0; private String[] ssCmdLines; private String sCmdLine; private String sStartPath; private Process proc = null; ProcessBuilder pb = null; public void ReStartProc() { try { if (lPeriod > 0) { lDelay = lPeriod - (System.currentTimeMillis() % lPeriod); Thread.sleep(lDelay); } else { Thread.sleep(10); } if (proc != null) { if (isRunning(proc)) { try { br.close(); } catch (Exception ex2) { System.out.println(ex2.getMessage()); } proc.destroy(); Thread.sleep(iPause); } } ssCmdLines = sCmdLine.split(" "); pb = new ProcessBuilder(ssCmdLines); if (sStartPath.length() > 1) { pb.directory(new File(sStartPath)); } pb.redirectErrorStream(true); proc = pb.start(); br = new BufferedReader(new InputStreamReader(proc.getInputStream())); } catch (Exception ex) { System.out.println(ex.getMessage()); } } public static boolean isRunning(Process process) { try { if (process == null) { return false; } process.exitValue(); return false; } catch (Exception e) { return true; } } }
SMXCore/SMXCore_NG
src/modules/MeterKamstrup.java
Java
gpl-3.0
7,242
<?php /************************************************************************ * This file is part of EspoCRM. * * EspoCRM - Open Source CRM application. * Copyright (C) 2014-2021 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko * Website: https://www.espocrm.com * * EspoCRM is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * EspoCRM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ namespace Espo\Hooks\Integration; use Espo\ORM\Entity; use Espo\Core\{ Utils\Config\ConfigWriter, }; class GoogleMaps { protected $configWriter; public function __construct(ConfigWriter $configWriter) { $this->configWriter = $configWriter; } public function afterSave(Entity $entity) { if ($entity->id !== 'GoogleMaps') { return; } if (!$entity->get('enabled') || !$entity->get('apiKey')) { $this->configWriter->set('googleMapsApiKey', null); $this->configWriter->save(); return; } $this->configWriter->set('googleMapsApiKey', $entity->get('apiKey')); $this->configWriter->save(); } }
ayman-alkom/espocrm
application/Espo/Hooks/Integration/GoogleMaps.php
PHP
gpl-3.0
2,094
import React from "react"; import PropTypes from "prop-types"; import styled from "@emotion/styled"; import { insertEmbeddedImages } from "../../../utils/embedded-images"; const RichTextareaFieldResponseWrapper = styled("div")(props => ({ // TODO: fluid video lineHeight: "1.3rem", "& img": { maxWidth: "100%", margin: "16px 0 0 0", }, "& ul": { marginTop: 0, marginBottom: "16px", fontWeight: "normal", }, "& p": { fontFamily: props.theme.text.bodyFontFamily, marginTop: 0, marginBottom: "16px", fontWeight: "normal", }, "& li": { fontFamily: props.theme.text.bodyFontFamily, fontWeight: "normal", }, "& a": { textDectoration: "none", fontWeight: "normal", }, "& h1,h2,h3,h4,h5,h6": { fontFamily: props.theme.text.titleFontFamily, margin: "16px 0 8px 0", }, })); const RichTextareaFieldResponse = props => { return ( <RichTextareaFieldResponseWrapper> <div className="rich-textarea-field-response" dangerouslySetInnerHTML={{ __html: insertEmbeddedImages(props.value, props.attachments), }} /> </RichTextareaFieldResponseWrapper> ); }; RichTextareaFieldResponse.propTypes = { attachments: PropTypes.array, value: PropTypes.string.isRequired, }; export default RichTextareaFieldResponse;
smartercleanup/platform
src/base/static/components/form-fields/types/rich-textarea-field-response.js
JavaScript
gpl-3.0
1,342
//******************************************************** // * // Instructor: Franck Xia * // Class: CS236 Fall 2002 * // Assignment: Program 6 * // Programmer: It's you * // File name: driver.cpp * // Function: driver program testing the parser * // * //******************************************************** #define SUCCESSFUL 0 #include <iostream> #include <list> #include <string> #include <fstream> #include <cstring> #include "signal.h" #include "parser.h" #include "scanner.h" using std::cout; using std::endl; char str_token_type[30][10]; // the array is global // The following part declare an array of record to keep a single character // lexeme and the type of lexeme useful for the parser const int CTL_CHAR_OFFSET = 32; lexeme_type_t lexeme_type[] = { // the first field of each record is a chacater, the second one its enTokens code // all the characters appear in the ascii code value ascedent order. // as the first 32 ascii chacaters are controlled characters, they are not // included. to access an appropriate record of a character, we can use the ascii // value of the character - 32 as the index to this array. { ' ', U },{'!',U},{'"',U},{'#',U}, { '$', SCANEOF },{'%',U},{'&',U},{ '\'',U}, { '(', LPAREN }, { ')', RPAREN }, { '*', MULTOP }, { '+', ADDOP }, { ',', COMMA }, { '-', SUBOP },{'.',U}, { '/', DIVOP }, { '0', U }, {'1',U}, {'2',U}, {'3',U}, {'4',U}, { '5', U }, {'6',U}, {'7',U}, {'8',U}, {'9',U}, { ':', U }, { ';', SEMICOL }, { '<', LESS }, { '=', ASSIGNOP }, { '>', GREAT },{'?',U},{'@',U }, { 'A', U },{'B',U},{'C',U},{'D',U},{'E',U},{'F',U},{'G',U}, { 'H',U},{'I',U},{'J',U},{'K',U},{'L',U},{'M',U},{'N',U}, { 'O',U},{'P',U},{'Q',U},{'R',U},{'S',U},{'T',U},{'U',U}, { 'V',U},{'W',U},{'X',U},{'Y',U},{'Z',U}, { '[', LBRACK },{'\\',U}, { ']', RBRACK },{'^',U},{'_',U},{'`',U}, { 'a', U },{'b',U},{'c',U},{'d',U},{'e',U},{'f',U},{'g',U}, { 'h', U },{'i',U},{'j',U},{'k',U},{'l',U},{'m',U},{'n',U}, { 'o', U },{'p',U},{'q',U},{'r',U},{'s',U},{'t',U},{'u',U}, { 'v', U },{'w',U},{'x',U},{'y',U},{'z',U}, { '{', U },{'|',U},{'}',U},{'~',U} }; int main() { // The following lines avoid a huge switch statement char tt[10]; int c; std::ifstream token_file( "tokens_file.dat" ); c = 0; // the starting value of enTokens type is set to 0 while ( c < 30 && token_file >> tt ) { std::strcpy( str_token_type[c++], tt ); } std::list<std::string> program_list; std::list<std::string>::const_iterator itrTest; CScanner scanner; Parser parsing; //program_list.push_back(std::string("a=b+3.14156 - 7.8182;$")); //program_list.push_back(std::string("a=c*b-d; $")); //program_list.push_back(std::string("a=c+b$ ")); //program_list.push_back(std::string("a=c*(b-d);$")); //program_list.push_back(std::string("a=c+b*d;$")); //program_list.push_back(std::string("a=(c+b)*d;$")); //program_list.push_back(std::string("a=(c+b)*d;$ ")); //program_list.push_back(std::string("a=(c+b)*d ; b=a-e*t; $")); //program_list.push_back(std::string("a=1+b $")); program_list.push_back(std::string("b=[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=[1.0,2.1;3.5,4.6]+1.0;$")); program_list.push_back(std::string("b=[1.0,2.1;3.5,4.6]-1.0;$")); program_list.push_back(std::string("b=1.0+[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=1.0-[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=2.0*[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=[1.0,2.1;3.5,4.6]*2.0;$")); program_list.push_back(std::string("b=1.0+2.1;$")); program_list.push_back(std::string("b=1.0-2.1;$")); program_list.push_back(std::string("b=3.0*2.1;$")); program_list.push_back(std::string("b=[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=[1.0,2.1;3.5];$")); program_list.push_back(std::string("b=[1.0,2.1;3.5,4.6]+[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=[1.0,2.1]+[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=[1.0,2.1;3.5,4.6]+[2.1;4.6];$")); program_list.push_back(std::string("b=[1.0,2.1;3.5,4.6]-[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=[1.0,2.1;3.5,4.6]-[1.0,2.1];$")); program_list.push_back(std::string("b=[1.0;3.5]-[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=[1.0,2.1;3.5,4.6]+[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=[1.0;3.5]*[1.0,2.1;3.5,4.6];$")); program_list.push_back(std::string("b=[1.0;3.5]*[1.0,2.1];$")); itrTest = program_list.begin(); while(itrTest != program_list.end()) { try { cout << *itrTest << endl; scanner.generate_token_list(*itrTest); // now scanner should contain a list of lexemes ready for parsing CToken_List ajb_temp=scanner.get_token_list(); parsing.parse(ajb_temp); cout << "\nA New Program\n\n"; } catch (CSignal e) { cout << e.get_message() <<endl <<endl <<endl; // Get the message } itrTest++; } return (SUCCESSFUL); }
Jmgiacone/CS5201
hw1/ex2/driver.cpp
C++
gpl-3.0
5,569
# -*- coding: utf-8 -*- """ Created on Thu Aug 31 16:04:18 2017 @author: adelpret """ import pinocchio as se3 import numpy as np from pinocchio import RobotWrapper from conversion_utils import config_sot_to_urdf, joints_sot_to_urdf, velocity_sot_to_urdf from dynamic_graph.sot.torque_control.inverse_dynamics_balance_controller import InverseDynamicsBalanceController from dynamic_graph.sot.torque_control.create_entities_utils import create_ctrl_manager import dynamic_graph.sot.torque_control.hrp2.balance_ctrl_sim_conf as balance_ctrl_conf import dynamic_graph.sot.torque_control.hrp2.control_manager_sim_conf as control_manager_conf from dynamic_graph.sot.torque_control.tests.robot_data_test import initRobotData np.set_printoptions(precision=3, suppress=True, linewidth=100); def create_balance_controller(dt, q, conf, robot_name='robot'): ctrl = InverseDynamicsBalanceController("invDynBalCtrl"); ctrl.q.value = tuple(q); ctrl.v.value = (NJ+6)*(0.0,); ctrl.wrench_right_foot.value = 6*(0.0,); ctrl.wrench_left_foot.value = 6*(0.0,); ctrl.posture_ref_pos.value = tuple(q[6:]); ctrl.posture_ref_vel.value = NJ*(0.0,); ctrl.posture_ref_acc.value = NJ*(0.0,); ctrl.com_ref_pos.value = (0., 0., 0.8); ctrl.com_ref_vel.value = 3*(0.0,); ctrl.com_ref_acc.value = 3*(0.0,); # ctrl.rotor_inertias.value = np.array(conf.ROTOR_INERTIAS); # ctrl.gear_ratios.value = conf.GEAR_RATIOS; ctrl.rotor_inertias.value = tuple([g*g*r for (g,r) in zip(conf.GEAR_RATIOS, conf.ROTOR_INERTIAS)]) ctrl.gear_ratios.value = NJ*(1.0,); ctrl.contact_normal.value = conf.FOOT_CONTACT_NORMAL; ctrl.contact_points.value = conf.RIGHT_FOOT_CONTACT_POINTS; ctrl.f_min.value = conf.fMin; ctrl.f_max_right_foot.value = conf.fMax; ctrl.f_max_left_foot.value = conf.fMax; ctrl.mu.value = conf.mu[0]; ctrl.weight_contact_forces.value = (1e2, 1e2, 1e0, 1e3, 1e3, 1e3); ctrl.kp_com.value = 3*(conf.kp_com,); ctrl.kd_com.value = 3*(conf.kd_com,); ctrl.kp_constraints.value = 6*(conf.kp_constr,); ctrl.kd_constraints.value = 6*(conf.kd_constr,); ctrl.kp_feet.value = 6*(conf.kp_feet,); ctrl.kd_feet.value = 6*(conf.kd_feet,); ctrl.kp_posture.value = conf.kp_posture; ctrl.kd_posture.value = conf.kd_posture; ctrl.kp_pos.value = conf.kp_pos; ctrl.kd_pos.value = conf.kd_pos; ctrl.w_com.value = conf.w_com; ctrl.w_feet.value = conf.w_feet; ctrl.w_forces.value = conf.w_forces; ctrl.w_posture.value = conf.w_posture; ctrl.w_base_orientation.value = conf.w_base_orientation; ctrl.w_torques.value = conf.w_torques; ctrl.active_joints.value = NJ*(1,); ctrl.init(dt, robot_name); return ctrl; print "*** UNIT TEST FOR INVERSE-DYNAMICS-BALANCE-CONTROLLER (IDBC) ***" print "This test computes the torques using the IDBC and compares them with" print "the torques computed using the desired joint accelerations and contact" print "wrenches computed by the IDBC. The two values should be identical." print "Some small differences are expected due to the precision loss when" print "Passing the parameters from python to c++." print "However, none of the following values should be larger than 1e-3.\n" N_TESTS = 100 dt = 0.001; NJ = initRobotData.nbJoints # robot configuration q_sot = np.array([-0.0027421149619457344, -0.0013842807952574399, 0.6421082804660067, -0.0005693871512031474, -0.0013094048521806974, 0.0028568508070167, -0.0006369040657361668, 0.002710094953239396, -0.48241992906618536, 0.9224570746372157, -0.43872624301275104, -0.0021586727954009096, -0.0023395862060549863, 0.0031045906573987617, -0.48278188636903313, 0.9218508861779927, -0.4380058166724791, -0.0025558837738616047, -0.012985322450541008, 0.04430420221275542, 0.37027327677517635, 1.4795064165303056, 0.20855551221055582, -0.13188842278441873, 0.005487207370709895, -0.2586657542648506, 2.6374918629921953, -0.004223605878088189, 0.17118034021053144, 0.24171737354070008, 0.11594430024547904, -0.05264225067057105, -0.4691871937149223, 0.0031522040623960016, 0.011836097472447007, 0.18425595002313025]); ctrl_manager = create_ctrl_manager(control_manager_conf, dt); ctrl = create_balance_controller(dt, q_sot, balance_ctrl_conf); robot = RobotWrapper(initRobotData.testRobotPath, [], se3.JointModelFreeFlyer()) index_rf = robot.index('RLEG_JOINT5'); index_lf = robot.index('LLEG_JOINT5'); Md = np.matrix(np.zeros((NJ+6,NJ+6))); gr = joints_sot_to_urdf(balance_ctrl_conf.GEAR_RATIOS); ri = joints_sot_to_urdf(balance_ctrl_conf.ROTOR_INERTIAS); for i in range(NJ): Md[6+i,6+i] = ri[i] * gr[i] * gr[i]; for i in range(N_TESTS): q_sot += 0.001*np.random.random(NJ+6); v_sot = np.random.random(NJ+6); q_pin = np.matrix(config_sot_to_urdf(q_sot)); v_pin = np.matrix(velocity_sot_to_urdf(v_sot)); ctrl.q.value = tuple(q_sot); ctrl.v.value = tuple(v_sot); ctrl.tau_des.recompute(i); tau_ctrl = joints_sot_to_urdf(np.array(ctrl.tau_des.value)); ctrl.dv_des.recompute(i); dv = velocity_sot_to_urdf(np.array(ctrl.dv_des.value)); M = Md + robot.mass(q_pin); h = robot.bias(q_pin, v_pin); ctrl.f_des_right_foot.recompute(i); ctrl.f_des_left_foot.recompute(i); f_rf = np.matrix(ctrl.f_des_right_foot.value).T; f_lf = np.matrix(ctrl.f_des_left_foot.value).T; J_rf = robot.jacobian(q_pin, index_rf); J_lf = robot.jacobian(q_pin, index_lf); tau_pin = M*np.matrix(dv).T + h - J_rf.T * f_rf - J_lf.T * f_lf; # ctrl.M.recompute(i); # M_ctrl = np.array(ctrl.M.value); print "norm(tau_ctrl-tau_pin) = %.4f"% np.linalg.norm(tau_ctrl - tau_pin[6:,0].T); print "norm(tau_pin[:6]) = %.4f"% np.linalg.norm(tau_pin[:6]); # print "q_pin:\n", q_pin; # print "tau_pin:\n", tau_pin[6:,0].T, "\n"; # print "tau ctrl:\n", tau_ctrl.T, "\n"; # print "dv = ", np.linalg.norm(dv); # print "f_rf:", f_rf.T, "\n"; # print "f_lf:", f_lf.T, "\n"; # print "h:", h.T, "\n"; # M_err = M-M_ctrl # print "M-M_ctrl = ", M_err.diagonal(), "\n" # for j in range(NJ+6): # print M_err[j,:];
proyan/sot-torque-control
unitTesting/unit_test_inverse_dynamics_balance_controller.py
Python
gpl-3.0
6,246
/* * Copyright (C) 2017 Saxon State and University Library Dresden (SLUB) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.slub.urn; import static de.slub.urn.URN.SCHEME; import static de.slub.urn.URNSyntaxError.syntaxError; import static de.slub.urn.URNSyntaxError.lengthError; import static de.slub.urn.URNSyntaxError.reservedIdentifier; /** * Represents a Namespace Identifier (NID) part of a Uniform Resource Identifier (URN). * * @author Ralf Claussnitzer * @see <a href="https://tools.ietf.org/html/rfc1737">Functional Requirements for Uniform Resource Names</a> * @see <a href="http://www.iana.org/assignments/urn-namespaces/urn-namespaces.xhtml">Official IANA Registry of URN Namespaces</a> */ abstract public class NamespaceIdentifier implements RFCSupport { private final String nid; /** * Creates a new {@code NamespaceIdentifier} instance. * * @param nid The Namespace Identifier literal * @throws URNSyntaxError if the given value is <pre>null</pre>, empty or invalid according to the * {@code isValidNamespaceIdentifier()} method. * @throws IllegalArgumentException if the parameter is null or empty */ public NamespaceIdentifier(String nid) throws URNSyntaxError { if ((nid == null) || (nid.isEmpty())) { throw new IllegalArgumentException("Namespace identifier part cannot be null or empty"); } if (SCHEME.equalsIgnoreCase(nid)) { throw reservedIdentifier(supportedRFC(), nid); } if (nid.length() > 32) { throw lengthError(supportedRFC(), nid); } final String validationError = validateNamespaceIdentifier(nid); if (validationError != null) { throw syntaxError(supportedRFC(), validationError); } this.nid = nid; } /** * Check if a given literal is a valid namespace identifier and return an error message if not. * * @param nid Namespace identifier literal * @return Error message, if the given string violates the rules for valid namespace identifiers. Null, if not. */ abstract protected String validateNamespaceIdentifier(String nid); /** * Create a new {@code NamespaceIdentifier} instance that is an exact copy of the given instance. * * @param instanceForCopying Base instance for copying * @throws IllegalArgumentException if parameter is null or empty */ public NamespaceIdentifier(NamespaceIdentifier instanceForCopying) { if (instanceForCopying == null) { throw new IllegalArgumentException("Namespace identifier cannot be null"); } nid = instanceForCopying.nid; } /** * Calculates hash code based on the string representation of this namespace identifier. * * @return The hash code for this namespace identifier instance. */ @Override public int hashCode() { return nid.hashCode(); } /** * Checks for equality with a given object. * * @param obj Object to check equality with * @return True, if the given object is a {@code NamespaceIdentifier} instance and is lexically equivalent to this instance. */ @Override public boolean equals(Object obj) { return (obj instanceof NamespaceIdentifier) && this.nid.equalsIgnoreCase(((NamespaceIdentifier) obj).nid); } /** * Returns the Namespace Identifier literal * * @return Namespace Identifier literal */ @Override public String toString() { return nid; } /** * @see RFCSupport#supports(RFC) */ @Override public boolean supports(RFC rfc) { return supportedRFC().equals(rfc); } }
slub/urnlib
src/main/java/de/slub/urn/NamespaceIdentifier.java
Java
gpl-3.0
4,394
<?php /* LOGIN */ $lang['welcome_login'] = "Aplikasi Kegiatan Harian - Masup"; $lang['identity_login'] = "Identitas"; $lang['password_login'] = "Kata Sandi"; /* USER */ /* DASHBOARD */ $lang['dash_title'] = "Dashboard - Aplikasi Kegiatan Harian"; ?>
mdestafadilah/akh
app/language/indonesian/akh_lang.php
PHP
gpl-3.0
254
package input; /** **@author yfhuang **created at 2014-2-26 */ import java.util.ArrayList; import java.util.List; public class EventQueueBus { private List<EventQueue> queues; //private long earliest; private CjEventListener cjeventlistener; private long eventstime=Long.MAX_VALUE; public EventQueueBus() { queues=new ArrayList<EventQueue>(); } /** * Returns all the loaded event queues * * @return all the loaded event queues */ public List<EventQueue> getEventQueues() { return this.queues; } public void addQueue(EventQueue eventqueue){ queues.add(eventqueue); } public List<CjEvent> nextEvents(){ //Log.write("excute EventQueueBus nextevent"); long earliest=Long.MAX_VALUE; EventQueue nextqueue=queues.get(0); //Log.write("next event queue:"+nextqueue.toString()); /* find the queue that has the next event */ for (EventQueue eq : queues) { //Log.write("nextqueue:"+eq.toString()+" "+eq.nextEventsTime()); if (eq.nextEventsTime() < earliest){ nextqueue = eq; earliest = eq.nextEventsTime(); } } cjeventlistener=nextqueue.getEventListener(); eventstime=earliest; List<CjEvent> eventslist=nextqueue.nextEvents(); return eventslist; } public long getNextEventsTime(){ long earliest=Long.MAX_VALUE; for (EventQueue eq : queues) { if (eq.nextEventsTime() < earliest){ earliest = eq.nextEventsTime(); } } return earliest; } public long getEventsTime(){ return eventstime; } public CjEventListener getEventListener(){ return cjeventlistener; } }
yongfenghuang/cjegsim
src/input/EventQueueBus.java
Java
gpl-3.0
1,561
/* * PCLanChat, the decentralized chat client * Copyright (C) 2017 Kuklin István * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <cstdlib> #include <QtWidgets> #include <QJsonDocument> #include <QStandardPaths> #include "Preferences.hpp" #include "Network.hpp" Preferences::Preferences() { if(!getPreferencesFolder().mkpath(getPreferencesFolder().path())) { QMessageBox messageBox; messageBox.setText("Error accessing configuration directory!"); return; } //creates the directory preferencesFile.setFileName("Preferences.json"); preferencesDialog = new PreferencesDialog(this); load(); } Preferences::~Preferences() { save(); delete preferencesDialog; } QDir Preferences::getPreferencesFolder() { return QDir(QStandardPaths::standardLocations(QStandardPaths::AppConfigLocation).first()); } void Preferences::openPreferences() { preferencesDialog->ui.NicknameEdit->setText(QString::fromStdString(getValues().nickname)); preferencesDialog->ui.ListenCheckBox->setChecked(getValues().listen); preferencesDialog->ui.SelfAdvertisingCheckBox->setChecked(getValues().selfAdvertising); preferencesDialog->ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); preferencesDialog->show(); } void Preferences::onApplied() { preferencesDialog->ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); values.nickname = preferencesDialog->ui.NicknameEdit->text().toStdString(); values.listen = preferencesDialog->ui.ListenCheckBox->isChecked(); values.selfAdvertising = preferencesDialog->ui.SelfAdvertisingCheckBox->isChecked(); server->restart(); } void Preferences::save() { QJsonObject jsonObject = preferencesJsonDocument.object(); jsonObject["nickname"] = QString::fromStdString(getValues().nickname); jsonObject["listen"] = getValues().listen; jsonObject["selfAdvertising"] = getValues().selfAdvertising; QDir::setCurrent(getPreferencesFolder().path()); preferencesFile.open(QIODevice::WriteOnly); preferencesJsonDocument.setObject(jsonObject); preferencesFile.write(preferencesJsonDocument.toJson()); preferencesFile.close(); } void Preferences::load() { QDir::setCurrent(getPreferencesFolder().path()); preferencesFile.open(QIODevice::ReadOnly); preferencesJsonDocument = QJsonDocument::fromJson(preferencesFile.readAll()); preferencesFile.close(); QJsonObject jsonObject = preferencesJsonDocument.object(); values.nickname = jsonObject["nickname"].toString().toStdString(); //yeah looks stupid :) values.listen = jsonObject["listen"].toBool(); values.selfAdvertising = jsonObject["selfAdvertising"].toBool(); } PreferencesDialog::PreferencesDialog(Preferences *preferencesInput) { preferences = preferencesInput; ui.setupUi(this); setFixedSize(352, 352); connect(ui.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(released()), preferences, SLOT(onApplied())); } void PreferencesDialog::bindPreferences(Preferences *preferencesInput) { preferences = preferencesInput; } void PreferencesDialog::accept() { preferences->onApplied(); hide(); } void PreferencesDialog::reject() { hide(); }
kuklinistvan/PCLanChat
Sources/Preferences.cpp
C++
gpl-3.0
3,795
/* Copyright 2014 Travel Modelling Group, Department of Civil Engineering, University of Toronto This file is part of XTMF. XTMF is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. XTMF is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with XTMF. If not, see <http://www.gnu.org/licenses/>. */ using System; using System.Collections.Generic; using XTMF; namespace TMG.Estimation.AI { // ReSharper disable once InconsistentNaming public class LinearGridAI : IEstimationAI { [RunParameter( "SubSections", 10, "The number of different sections to break the space into." )] public int Subsections; [RunParameter( "Maximize", false, "Should we maximize the result or minimize it?" )] public bool Maximize; private ParameterSetting[] LocalSpaces; [RootModule] public IEstimationHost Root; public List<Job> CreateJobsForIteration() { var iteration = Root.CurrentIteration; if ( iteration == 0 ) { SetupParameters( Root.Parameters ); } var numberOfGaps = Subsections; var currentParameter = iteration % LocalSpaces.Length; var ret = new List<Job>(); var min = LocalSpaces[currentParameter].Minimum; var max = LocalSpaces[currentParameter].Maximum; for ( int i = 0; i < numberOfGaps; i++ ) { var job = CleanJob( LocalSpaces ); job.Parameters[currentParameter].Current = ( ( (float)i / ( numberOfGaps - 1 ) ) * ( max - min ) ) + min; ret.Add( job ); } return ret; } private Job CleanJob(ParameterSetting[] parameters) { var ret = new Job(); ret.Processed = false; ret.ProcessedBy = null; ret.Value = float.NaN; ret.Processing = false; ret.Parameters = new ParameterSetting[parameters.Length]; for ( int i = 0; i < ret.Parameters.Length; i++ ) { ret.Parameters[i] = new ParameterSetting() { Maximum = parameters[i].Maximum, Minimum = parameters[i].Minimum, Current = parameters[i].Current }; } return ret; } private void SetupParameters(List<ParameterSetting> list) { var param = new ParameterSetting[list.Count]; for ( int i = 0; i < param.Length; i++ ) { var other = list[i]; param[i] = new ParameterSetting(); param[i].Minimum = other.Minimum; param[i].Maximum = other.Maximum; param[i].Current = ( other.Maximum + other.Minimum ) / 2; } LocalSpaces = param; } private int FindBest(List<Job> jobs) { int best = 0; if ( Maximize ) { for ( int i = 1; i < jobs.Count; i++ ) { if ( jobs[i].Value > jobs[best].Value ) { best = i; } } } else { for ( int i = 1; i < jobs.Count; i++ ) { if ( jobs[i].Value < jobs[best].Value ) { best = i; } } } return best; } public void IterationComplete() { // update spaces var iteration = Root.CurrentIteration; var currentParameter = iteration % LocalSpaces.Length; var jobs = Root.CurrentJobs; int best = FindBest( jobs ); int minimumIndex = best < 1 ? 0 : best - 1; int maximumIndex = best >= jobs.Count - 1 ? jobs.Count - 1 : best + 1; LocalSpaces[currentParameter].Minimum = jobs[minimumIndex].Parameters[currentParameter].Current; LocalSpaces[currentParameter].Maximum = jobs[maximumIndex].Parameters[currentParameter].Current; LocalSpaces[currentParameter].Current = ( LocalSpaces[currentParameter].Maximum + LocalSpaces[currentParameter].Minimum ) / 2; } public string Name { get; set; } public float Progress { get { return 0f; } } public Tuple<byte, byte, byte> ProgressColour { get { return null; } } public bool RuntimeValidation(ref string error) { return true; } } }
TravelModellingGroup/XTMF
Code/TMG.Estimation/AI/LinearGridAI.cs
C#
gpl-3.0
5,218
/* * EVE Swagger Interface * An OpenAPI for EVE Online * * OpenAPI spec version: 0.4.9.dev1 * * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ package ru.tmin10.EVESecurityService.serverApi.model; import java.util.Objects; import com.google.gson.annotations.SerializedName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; /** * Not found */ @ApiModel(description = "Not found") @javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2017-06-11T18:18:08.749+04:00") public class GetUniversePlanetsPlanetIdNotFound { @SerializedName("error") private String error = null; public GetUniversePlanetsPlanetIdNotFound error(String error) { this.error = error; return this; } /** * Not found message * @return error **/ @ApiModelProperty(example = "null", value = "Not found message") public String getError() { return error; } public void setError(String error) { this.error = error; } @Override public boolean equals(java.lang.Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } GetUniversePlanetsPlanetIdNotFound getUniversePlanetsPlanetIdNotFound = (GetUniversePlanetsPlanetIdNotFound) o; return Objects.equals(this.error, getUniversePlanetsPlanetIdNotFound.error); } @Override public int hashCode() { return Objects.hash(error); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class GetUniversePlanetsPlanetIdNotFound {\n"); sb.append(" error: ").append(toIndentedString(error)).append("\n"); sb.append("}"); return sb.toString(); } /** * Convert the given object to string with each line indented by 4 spaces * (except the first line). */ private String toIndentedString(java.lang.Object o) { if (o == null) { return "null"; } return o.toString().replace("\n", "\n "); } }
Tmin10/EVE-Security-Service
server-api/src/main/java/ru/tmin10/EVESecurityService/serverApi/model/GetUniversePlanetsPlanetIdNotFound.java
Java
gpl-3.0
2,163
<?php /** * @package wp-content-aware-engine * @author Joachim Jensen <joachim@dev.institute> * @license GPLv3 * @copyright 2022 by Joachim Jensen */ defined('ABSPATH') || exit; if (!class_exists('WPCATypeManager')) { /** * Manage module objects */ final class WPCATypeManager extends WPCACollection { /** * Constructor */ public function __construct() { parent::__construct(); add_action( 'init', [$this,'set_modules'], 999 ); } /** * @param string $name * @return $this */ public function add($name) { return parent::put($name, new WPCACollection()); } /** * Set initial modules * * @since 4.0 * @return void */ public function set_modules() { do_action('wpca/types/init', $this); $modules = [ 'static', 'post_type', 'author', 'page_template', 'taxonomy', 'date', 'bbpress', 'bp_member', 'pods', 'polylang', 'qtranslate', 'translatepress', 'transposh', 'weglot', 'wpml' ]; foreach ($modules as $name) { $class_name = WPCACore::CLASS_PREFIX . 'Module_' . $name; if (!class_exists($class_name)) { continue; } $class = new $class_name(); if (!($class instanceof WPCAModule_Base) || !$class->can_enable()) { continue; } foreach ($this->all() as $post_type) { $post_type->put($name, $class); } } do_action('wpca/modules/init', $this); //initiate all modules once with backwards compatibility on can_enable() $initiated = []; foreach ($this->all() as $post_type_name => $post_type) { if (!WPCACore::get_option($post_type_name, 'legacy.date_module', false)) { $post_type->remove('date'); } foreach ($post_type->all() as $key => $module) { if (!isset($initiated[$key])) { $initiated[$key] = 1; $module->initiate(); } } } } } }
intoxstudio/wp-content-aware-engine
typemanager.php
PHP
gpl-3.0
2,670
""" YieldFrom astroid node This node represents the Python "yield from" statement, which functions similarly to the "yield" statement except that the generator can delegate some generating work to another generator. Attributes: - value (GeneratorExp) - The generator that this YieldFrom is delegating work to. Example: - value -> Call(range, Name('g', Load())) """ def fun(g): yield from range(g)
shweta97/pyta
nodes/YieldFrom.py
Python
gpl-3.0
423
# encoding: utf-8 import datetime from south.db import db from south.v2 import SchemaMigration from django.db import models class Migration(SchemaMigration): def forwards(self, orm): # Adding field 'GeoNamesMatchingLogMatchedPlaces.remark' db.add_column('united_geonames_geonamesmatchinglogmatchedplaces', 'remark', self.gf('django.db.models.fields.TextField')(null=True, blank=True), keep_default=False) def backwards(self, orm): # Deleting field 'GeoNamesMatchingLogMatchedPlaces.remark' db.delete_column('united_geonames_geonamesmatchinglogmatchedplaces', 'remark') models = { 'auth.group': { 'Meta': {'object_name': 'Group'}, 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) }, 'auth.permission': { 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '80'}) }, 'auth.user': { 'Meta': {'object_name': 'User'}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2014, 7, 25, 14, 53, 19, 34425)'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2014, 7, 25, 14, 53, 19, 34316)'}), 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) }, 'contenttypes.contenttype': { 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) }, 'united_geonames.geonamesmatchinglogmatch': { 'Meta': {'ordering': "['-matching_index']", 'object_name': 'GeoNamesMatchingLogMatch'}, 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True'}), 'display_for_users': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'matching_index': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '233', 'null': 'True', 'blank': 'True'}), 'number_of_alternatives': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}), 'start_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}) }, 'united_geonames.geonamesmatchinglogmatchedplaces': { 'Meta': {'object_name': 'GeoNamesMatchingLogMatchedPlaces'}, 'best_match': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'geographical_distance': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'matchinglogmatch': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'matched'", 'null': 'True', 'to': "orm['united_geonames.GeoNamesMatchingLogMatch']"}), 'ngram_distance': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), 'percentage': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), 'remark': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), 'united_geoname': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['united_geonames.UnitedGeoName']", 'null': 'True', 'blank': 'True'}) }, 'united_geonames.unitedgeoname': { 'Meta': {'object_name': 'UnitedGeoName'}, 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'main_name': ('django.db.models.fields.CharField', [], {'max_length': '300'}) }, 'united_geonames.unitedgeonamesynonim': { 'Meta': {'object_name': 'UnitedGeoNameSynonim'}, 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True'}), 'coordinates': ('django.contrib.gis.db.models.fields.PointField', [], {'null': 'True', 'spatial_index': 'False'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'identifier': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}), 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}), 'region': ('django.db.models.fields.CharField', [], {'max_length': '300', 'null': 'True', 'blank': 'True'}), 'subregion': ('django.db.models.fields.CharField', [], {'max_length': '300', 'null': 'True', 'blank': 'True'}), 'synonim_content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'synonim_content_type_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}), 'synonim_name': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}), 'synonim_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}), 'united_geoname': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'geonames'", 'null': 'True', 'to': "orm['united_geonames.UnitedGeoName']"}) }, 'united_geonames.usergeoname': { 'Meta': {'object_name': 'UserGeoName'}, 'coordinates': ('django.contrib.gis.db.models.fields.PointField', [], {'null': 'True', 'spatial_index': 'False', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'region': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'subregion': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}) }, 'united_geonames.userproject': { 'Meta': {'object_name': 'UserProject'}, 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), 'user': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}) } } complete_apps = ['united_geonames']
justinasjaronis/hpn
united_geonames/migrations/0015_auto__add_field_geonamesmatchinglogmatchedplaces_remark.py
Python
gpl-3.0
9,334
package com.basicer.parchment.parameters; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import com.basicer.parchment.Context; public class ItemParameter extends Parameter { private ItemStack self; public ItemParameter(ItemStack self) { this.self = self; } @Override public Class<ItemStack> getUnderlyingType() { return ItemStack.class; } public ItemStack asItemStack(Context ctx) { return self; } public String asString(Context ctx) { ItemMeta m = self.getItemMeta(); if ( m != null && m.getDisplayName() != null ) return m.getDisplayName(); return self.getType().name(); } }
basicer/parchment
src/main/java/com/basicer/parchment/parameters/ItemParameter.java
Java
gpl-3.0
671
/* Copyright (c) 2005-2021 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include <string.h> /* for memset */ #include <errno.h> #include "tbbmalloc_internal.h" namespace rml { namespace internal { /*********** Code to acquire memory from the OS or other executive ****************/ /* syscall/malloc can set non-zero errno in case of failure, but later allocator might be able to find memory to fulfill the request. And we do not want changing of errno by successful scalable_malloc call. To support this, restore old errno in (get|free)RawMemory, and set errno in frontend just before returning to user code. Please note: every syscall/libc call used inside scalable_malloc that sets errno must be protected this way, not just memory allocation per se. */ #if USE_DEFAULT_MEMORY_MAPPING #include "MapMemory.h" #else /* assume MapMemory and UnmapMemory are customized */ #endif void* getRawMemory (size_t size, PageType pageType) { return MapMemory(size, pageType); } int freeRawMemory (void *object, size_t size) { return UnmapMemory(object, size); } #if CHECK_ALLOCATION_RANGE void Backend::UsedAddressRange::registerAlloc(uintptr_t left, uintptr_t right) { MallocMutex::scoped_lock lock(mutex); if (left < leftBound.load(std::memory_order_relaxed)) leftBound.store(left, std::memory_order_relaxed); if (right > rightBound.load(std::memory_order_relaxed)) rightBound.store(right, std::memory_order_relaxed); MALLOC_ASSERT(leftBound.load(std::memory_order_relaxed), ASSERT_TEXT); MALLOC_ASSERT(leftBound.load(std::memory_order_relaxed) < rightBound.load(std::memory_order_relaxed), ASSERT_TEXT); MALLOC_ASSERT(leftBound.load(std::memory_order_relaxed) <= left && right <= rightBound.load(std::memory_order_relaxed), ASSERT_TEXT); } void Backend::UsedAddressRange::registerFree(uintptr_t left, uintptr_t right) { MallocMutex::scoped_lock lock(mutex); if (leftBound.load(std::memory_order_relaxed) == left) { if (rightBound.load(std::memory_order_relaxed) == right) { leftBound.store(ADDRESS_UPPER_BOUND, std::memory_order_relaxed); rightBound.store(0, std::memory_order_relaxed); } else leftBound.store(right, std::memory_order_relaxed); } else if (rightBound.load(std::memory_order_relaxed) == right) rightBound.store(left, std::memory_order_relaxed); MALLOC_ASSERT((!rightBound.load(std::memory_order_relaxed) && leftBound.load(std::memory_order_relaxed) == ADDRESS_UPPER_BOUND) || leftBound.load(std::memory_order_relaxed) < rightBound.load(std::memory_order_relaxed), ASSERT_TEXT); } #endif // CHECK_ALLOCATION_RANGE // Initialized in frontend inside defaultMemPool extern HugePagesStatus hugePages; void *Backend::allocRawMem(size_t &size) { void *res = NULL; size_t allocSize = 0; if (extMemPool->userPool()) { if (extMemPool->fixedPool && bootsrapMemDone == bootsrapMemStatus.load(std::memory_order_acquire)) return NULL; MALLOC_ASSERT(bootsrapMemStatus != bootsrapMemNotDone, "Backend::allocRawMem() called prematurely?"); // TODO: support for raw mem not aligned at sizeof(uintptr_t) // memory from fixed pool is asked once and only once allocSize = alignUpGeneric(size, extMemPool->granularity); res = (*extMemPool->rawAlloc)(extMemPool->poolId, allocSize); } else { // Align allocation on page size size_t pageSize = hugePages.isEnabled ? hugePages.getGranularity() : extMemPool->granularity; MALLOC_ASSERT(pageSize, "Page size cannot be zero."); allocSize = alignUpGeneric(size, pageSize); // If user requested huge pages and they are available, try to use preallocated ones firstly. // If there are none, lets check transparent huge pages support and use them instead. if (hugePages.isEnabled) { if (hugePages.isHPAvailable) { res = getRawMemory(allocSize, PREALLOCATED_HUGE_PAGE); } if (!res && hugePages.isTHPAvailable) { res = getRawMemory(allocSize, TRANSPARENT_HUGE_PAGE); } } if (!res) { res = getRawMemory(allocSize, REGULAR); } } if (res) { MALLOC_ASSERT(allocSize > 0, "Invalid size of an allocated region."); size = allocSize; if (!extMemPool->userPool()) usedAddrRange.registerAlloc((uintptr_t)res, (uintptr_t)res+size); #if MALLOC_DEBUG volatile size_t curTotalSize = totalMemSize; // to read global value once MALLOC_ASSERT(curTotalSize+size > curTotalSize, "Overflow allocation size."); #endif totalMemSize.fetch_add(size); } return res; } bool Backend::freeRawMem(void *object, size_t size) { bool fail; #if MALLOC_DEBUG volatile size_t curTotalSize = totalMemSize; // to read global value once MALLOC_ASSERT(curTotalSize-size < curTotalSize, "Negative allocation size."); #endif totalMemSize.fetch_sub(size); if (extMemPool->userPool()) { MALLOC_ASSERT(!extMemPool->fixedPool, "No free for fixed-size pools."); fail = (*extMemPool->rawFree)(extMemPool->poolId, object, size); } else { usedAddrRange.registerFree((uintptr_t)object, (uintptr_t)object + size); fail = freeRawMemory(object, size); } // TODO: use result in all freeRawMem() callers return !fail; } /********* End memory acquisition code ********************************/ // Protected object size. After successful locking returns size of locked block, // and releasing requires setting block size. class GuardedSize : tbb::detail::no_copy { std::atomic<uintptr_t> value; public: enum State { LOCKED, COAL_BLOCK, // block is coalescing now MAX_LOCKED_VAL = COAL_BLOCK, LAST_REGION_BLOCK, // used to mark last block in region // values after this are "normal" block sizes MAX_SPEC_VAL = LAST_REGION_BLOCK }; void initLocked() { value.store(LOCKED, std::memory_order_release); } // TBB_REVAMP_TODO: was relaxed void makeCoalscing() { MALLOC_ASSERT(value.load(std::memory_order_relaxed) == LOCKED, ASSERT_TEXT); value.store(COAL_BLOCK, std::memory_order_release); // TBB_REVAMP_TODO: was relaxed } size_t tryLock(State state) { MALLOC_ASSERT(state <= MAX_LOCKED_VAL, ASSERT_TEXT); size_t sz = value.load(std::memory_order_acquire); for (;;) { if (sz <= MAX_LOCKED_VAL) { break; } if (value.compare_exchange_strong(sz, state)) { break; } } return sz; } void unlock(size_t size) { MALLOC_ASSERT(value.load(std::memory_order_relaxed) <= MAX_LOCKED_VAL, "The lock is not locked"); MALLOC_ASSERT(size > MAX_LOCKED_VAL, ASSERT_TEXT); value.store(size, std::memory_order_release); } bool isLastRegionBlock() const { return value.load(std::memory_order_relaxed) == LAST_REGION_BLOCK; } friend void Backend::IndexedBins::verify(); }; struct MemRegion { MemRegion *next, // keep all regions in any pool to release all them on *prev; // pool destroying, 2-linked list to release individual // regions. size_t allocSz, // got from pool callback blockSz; // initial and maximal inner block size MemRegionType type; }; // this data must be unmodified while block is in use, so separate it class BlockMutexes { protected: GuardedSize myL, // lock for me leftL; // lock for left neighbor }; class FreeBlock : BlockMutexes { public: static const size_t minBlockSize; friend void Backend::IndexedBins::verify(); FreeBlock *prev, // in 2-linked list related to bin *next, *nextToFree; // used to form a queue during coalescing // valid only when block is in processing, i.e. one is not free and not size_t sizeTmp; // used outside of backend int myBin; // bin that is owner of the block bool slabAligned; bool blockInBin; // this block in myBin already FreeBlock *rightNeig(size_t sz) const { MALLOC_ASSERT(sz, ASSERT_TEXT); return (FreeBlock*)((uintptr_t)this+sz); } FreeBlock *leftNeig(size_t sz) const { MALLOC_ASSERT(sz, ASSERT_TEXT); return (FreeBlock*)((uintptr_t)this - sz); } void initHeader() { myL.initLocked(); leftL.initLocked(); } void setMeFree(size_t size) { myL.unlock(size); } size_t trySetMeUsed(GuardedSize::State s) { return myL.tryLock(s); } bool isLastRegionBlock() const { return myL.isLastRegionBlock(); } void setLeftFree(size_t sz) { leftL.unlock(sz); } size_t trySetLeftUsed(GuardedSize::State s) { return leftL.tryLock(s); } size_t tryLockBlock() { size_t rSz, sz = trySetMeUsed(GuardedSize::LOCKED); if (sz <= GuardedSize::MAX_LOCKED_VAL) return false; rSz = rightNeig(sz)->trySetLeftUsed(GuardedSize::LOCKED); if (rSz <= GuardedSize::MAX_LOCKED_VAL) { setMeFree(sz); return false; } MALLOC_ASSERT(rSz == sz, ASSERT_TEXT); return sz; } void markCoalescing(size_t blockSz) { myL.makeCoalscing(); rightNeig(blockSz)->leftL.makeCoalscing(); sizeTmp = blockSz; nextToFree = NULL; } void markUsed() { myL.initLocked(); rightNeig(sizeTmp)->leftL.initLocked(); nextToFree = NULL; } static void markBlocks(FreeBlock *fBlock, int num, size_t size) { for (int i=1; i<num; i++) { fBlock = (FreeBlock*)((uintptr_t)fBlock + size); fBlock->initHeader(); } } }; // Last block in any region. Its "size" field is GuardedSize::LAST_REGION_BLOCK, // This kind of blocks used to find region header // and have a possibility to return region back to OS struct LastFreeBlock : public FreeBlock { MemRegion *memRegion; }; const size_t FreeBlock::minBlockSize = sizeof(FreeBlock); inline bool BackendSync::waitTillBlockReleased(intptr_t startModifiedCnt) { AtomicBackoff backoff; #if __TBB_MALLOC_BACKEND_STAT class ITT_Guard { void *ptr; public: ITT_Guard(void *p) : ptr(p) { MALLOC_ITT_SYNC_PREPARE(ptr); } ~ITT_Guard() { MALLOC_ITT_SYNC_ACQUIRED(ptr); } }; ITT_Guard ittGuard(&inFlyBlocks); #endif for (intptr_t myBinsInFlyBlocks = inFlyBlocks.load(std::memory_order_acquire), myCoalescQInFlyBlocks = backend->blocksInCoalescing(); ; backoff.pause()) { MALLOC_ASSERT(myBinsInFlyBlocks>=0 && myCoalescQInFlyBlocks>=0, NULL); intptr_t currBinsInFlyBlocks = inFlyBlocks.load(std::memory_order_acquire), currCoalescQInFlyBlocks = backend->blocksInCoalescing(); WhiteboxTestingYield(); // Stop waiting iff: // 1) blocks were removed from processing, not added if (myBinsInFlyBlocks > currBinsInFlyBlocks // 2) released during delayed coalescing queue || myCoalescQInFlyBlocks > currCoalescQInFlyBlocks) break; // 3) if there are blocks in coalescing, and no progress in its processing, // try to scan coalescing queue and stop waiting, if changes were made // (if there are no changes and in-fly blocks exist, we continue // waiting to not increase load on coalescQ) if (currCoalescQInFlyBlocks > 0 && backend->scanCoalescQ(/*forceCoalescQDrop=*/false)) break; // 4) when there are no blocks if (!currBinsInFlyBlocks && !currCoalescQInFlyBlocks) // re-scan make sense only if bins were modified since scanned return startModifiedCnt != getNumOfMods(); myBinsInFlyBlocks = currBinsInFlyBlocks; myCoalescQInFlyBlocks = currCoalescQInFlyBlocks; } return true; } void CoalRequestQ::putBlock(FreeBlock *fBlock) { MALLOC_ASSERT(fBlock->sizeTmp >= FreeBlock::minBlockSize, ASSERT_TEXT); fBlock->markUsed(); // the block is in the queue, do not forget that it's here inFlyBlocks++; FreeBlock *myBlToFree = blocksToFree.load(std::memory_order_acquire); for (;;) { fBlock->nextToFree = myBlToFree; if (blocksToFree.compare_exchange_strong(myBlToFree, fBlock)) { return; } } } FreeBlock *CoalRequestQ::getAll() { for (;;) { FreeBlock *myBlToFree = blocksToFree.load(std::memory_order_acquire); if (!myBlToFree) { return NULL; } else { if (blocksToFree.compare_exchange_strong(myBlToFree, 0)) { return myBlToFree; } else { continue; } } } } inline void CoalRequestQ::blockWasProcessed() { bkndSync->binsModified(); int prev = inFlyBlocks.fetch_sub(1); MALLOC_ASSERT(prev > 0, ASSERT_TEXT); } // Try to get a block from a bin. // If the remaining free space would stay in the same bin, // split the block without removing it. // If the free space should go to other bin(s), remove the block. // alignedBin is true, if all blocks in the bin have slab-aligned right side. FreeBlock *Backend::IndexedBins::getFromBin(int binIdx, BackendSync *sync, size_t size, bool needAlignedRes, bool alignedBin, bool wait, int *binLocked) { Bin *b = &freeBins[binIdx]; try_next: FreeBlock *fBlock = NULL; if (!b->empty()) { bool locked; MallocMutex::scoped_lock scopedLock(b->tLock, wait, &locked); if (!locked) { if (binLocked) (*binLocked)++; return NULL; } for (FreeBlock *curr = b->head.load(std::memory_order_relaxed); curr; curr = curr->next) { size_t szBlock = curr->tryLockBlock(); if (!szBlock) { // block is locked, re-do bin lock, as there is no place to spin // while block coalescing goto try_next; } // GENERAL CASE if (alignedBin || !needAlignedRes) { size_t splitSz = szBlock - size; // If we got a block as split result, it must have a room for control structures. if (szBlock >= size && (splitSz >= FreeBlock::minBlockSize || !splitSz)) fBlock = curr; } else { // SPECIAL CASE, to get aligned block from unaligned bin we have to cut the middle of a block // and return remaining left and right part. Possible only in fixed pool scenario, assert for this // is set inside splitBlock() function. void *newB = alignUp(curr, slabSize); uintptr_t rightNew = (uintptr_t)newB + size; uintptr_t rightCurr = (uintptr_t)curr + szBlock; // Check if the block size is sufficient, // and also left and right split results are either big enough or non-existent if (rightNew <= rightCurr && (newB == curr || ((uintptr_t)newB - (uintptr_t)curr) >= FreeBlock::minBlockSize) && (rightNew == rightCurr || (rightCurr - rightNew) >= FreeBlock::minBlockSize)) fBlock = curr; } if (fBlock) { // consume must be called before result of removing from a bin is visible externally. sync->blockConsumed(); // TODO: think about cases when block stays in the same bin b->removeBlock(fBlock); if (freeBins[binIdx].empty()) bitMask.set(binIdx, false); fBlock->sizeTmp = szBlock; break; } else { // block size is not valid, search for next block in the bin curr->setMeFree(szBlock); curr->rightNeig(szBlock)->setLeftFree(szBlock); } } } return fBlock; } bool Backend::IndexedBins::tryReleaseRegions(int binIdx, Backend *backend) { Bin *b = &freeBins[binIdx]; FreeBlock *fBlockList = NULL; // got all blocks from the bin and re-do coalesce on them // to release single-block regions try_next: if (!b->empty()) { MallocMutex::scoped_lock binLock(b->tLock); for (FreeBlock *curr = b->head.load(std::memory_order_relaxed); curr; ) { size_t szBlock = curr->tryLockBlock(); if (!szBlock) goto try_next; FreeBlock *next = curr->next; b->removeBlock(curr); curr->sizeTmp = szBlock; curr->nextToFree = fBlockList; fBlockList = curr; curr = next; } } return backend->coalescAndPutList(fBlockList, /*forceCoalescQDrop=*/true, /*reportBlocksProcessed=*/false); } void Backend::Bin::removeBlock(FreeBlock *fBlock) { MALLOC_ASSERT(fBlock->next||fBlock->prev||fBlock== head.load(std::memory_order_relaxed), "Detected that a block is not in the bin."); if (head.load(std::memory_order_relaxed) == fBlock) head.store(fBlock->next, std::memory_order_relaxed); if (tail == fBlock) tail = fBlock->prev; if (fBlock->prev) fBlock->prev->next = fBlock->next; if (fBlock->next) fBlock->next->prev = fBlock->prev; } void Backend::IndexedBins::addBlock(int binIdx, FreeBlock *fBlock, size_t /* blockSz */, bool addToTail) { Bin *b = &freeBins[binIdx]; fBlock->myBin = binIdx; fBlock->next = fBlock->prev = NULL; { MallocMutex::scoped_lock scopedLock(b->tLock); if (addToTail) { fBlock->prev = b->tail; b->tail = fBlock; if (fBlock->prev) fBlock->prev->next = fBlock; if (!b->head.load(std::memory_order_relaxed)) b->head.store(fBlock, std::memory_order_relaxed); } else { fBlock->next = b->head.load(std::memory_order_relaxed); b->head.store(fBlock, std::memory_order_relaxed); if (fBlock->next) fBlock->next->prev = fBlock; if (!b->tail) b->tail = fBlock; } } bitMask.set(binIdx, true); } bool Backend::IndexedBins::tryAddBlock(int binIdx, FreeBlock *fBlock, bool addToTail) { bool locked; Bin *b = &freeBins[binIdx]; fBlock->myBin = binIdx; if (addToTail) { fBlock->next = NULL; { MallocMutex::scoped_lock scopedLock(b->tLock, /*wait=*/false, &locked); if (!locked) return false; fBlock->prev = b->tail; b->tail = fBlock; if (fBlock->prev) fBlock->prev->next = fBlock; if (!b->head.load(std::memory_order_relaxed)) b->head.store(fBlock, std::memory_order_relaxed); } } else { fBlock->prev = NULL; { MallocMutex::scoped_lock scopedLock(b->tLock, /*wait=*/false, &locked); if (!locked) return false; fBlock->next = b->head.load(std::memory_order_relaxed); b->head.store(fBlock, std::memory_order_relaxed); if (fBlock->next) fBlock->next->prev = fBlock; if (!b->tail) b->tail = fBlock; } } bitMask.set(binIdx, true); return true; } void Backend::IndexedBins::reset() { for (unsigned i=0; i<Backend::freeBinsNum; i++) freeBins[i].reset(); bitMask.reset(); } void Backend::IndexedBins::lockRemoveBlock(int binIdx, FreeBlock *fBlock) { MallocMutex::scoped_lock scopedLock(freeBins[binIdx].tLock); freeBins[binIdx].removeBlock(fBlock); if (freeBins[binIdx].empty()) bitMask.set(binIdx, false); } bool ExtMemoryPool::regionsAreReleaseable() const { return !keepAllMemory && !delayRegsReleasing; } FreeBlock *Backend::splitBlock(FreeBlock *fBlock, int num, size_t size, bool blockIsAligned, bool needAlignedBlock) { const size_t totalSize = num * size; // SPECIAL CASE, for unaligned block we have to cut the middle of a block // and return remaining left and right part. Possible only in a fixed pool scenario. if (needAlignedBlock && !blockIsAligned) { MALLOC_ASSERT(extMemPool->fixedPool, "Aligned block request from unaligned bin possible only in fixed pool scenario."); // Space to use is in the middle FreeBlock *newBlock = alignUp(fBlock, slabSize); FreeBlock *rightPart = (FreeBlock*)((uintptr_t)newBlock + totalSize); uintptr_t fBlockEnd = (uintptr_t)fBlock + fBlock->sizeTmp; // Return free right part if ((uintptr_t)rightPart != fBlockEnd) { rightPart->initHeader(); // to prevent coalescing rightPart with fBlock size_t rightSize = fBlockEnd - (uintptr_t)rightPart; coalescAndPut(rightPart, rightSize, toAlignedBin(rightPart, rightSize)); } // And free left part if (newBlock != fBlock) { newBlock->initHeader(); // to prevent coalescing fBlock with newB size_t leftSize = (uintptr_t)newBlock - (uintptr_t)fBlock; coalescAndPut(fBlock, leftSize, toAlignedBin(fBlock, leftSize)); } fBlock = newBlock; } else if (size_t splitSize = fBlock->sizeTmp - totalSize) { // need to split the block // GENERAL CASE, cut the left or right part of the block FreeBlock *splitBlock = NULL; if (needAlignedBlock) { // For slab aligned blocks cut the right side of the block // and return it to a requester, original block returns to backend splitBlock = fBlock; fBlock = (FreeBlock*)((uintptr_t)splitBlock + splitSize); fBlock->initHeader(); } else { // For large object blocks cut original block and put free righ part to backend splitBlock = (FreeBlock*)((uintptr_t)fBlock + totalSize); splitBlock->initHeader(); } // Mark free block as it`s parent only when the requested type (needAlignedBlock) // and returned from Bins/OS block (isAligned) are equal (XOR operation used) bool markAligned = (blockIsAligned ^ needAlignedBlock) ? toAlignedBin(splitBlock, splitSize) : blockIsAligned; coalescAndPut(splitBlock, splitSize, markAligned); } MALLOC_ASSERT(!needAlignedBlock || isAligned(fBlock, slabSize), "Expect to get aligned block, if one was requested."); FreeBlock::markBlocks(fBlock, num, size); return fBlock; } size_t Backend::getMaxBinnedSize() const { return hugePages.isEnabled && !inUserPool() ? maxBinned_HugePage : maxBinned_SmallPage; } inline bool Backend::MaxRequestComparator::operator()(size_t oldMaxReq, size_t requestSize) const { return requestSize > oldMaxReq && requestSize < backend->getMaxBinnedSize(); } // last chance to get memory FreeBlock *Backend::releaseMemInCaches(intptr_t startModifiedCnt, int *lockedBinsThreshold, int numOfLockedBins) { // something released from caches if (extMemPool->hardCachesCleanup() // ..or can use blocks that are in processing now || bkndSync.waitTillBlockReleased(startModifiedCnt)) return (FreeBlock*)VALID_BLOCK_IN_BIN; // OS can't give us more memory, but we have some in locked bins if (*lockedBinsThreshold && numOfLockedBins) { *lockedBinsThreshold = 0; return (FreeBlock*)VALID_BLOCK_IN_BIN; } return NULL; // nothing found, give up } FreeBlock *Backend::askMemFromOS(size_t blockSize, intptr_t startModifiedCnt, int *lockedBinsThreshold, int numOfLockedBins, bool *splittableRet, bool needSlabRegion) { FreeBlock *block; // The block sizes can be divided into 3 groups: // 1. "quite small": popular object size, we are in bootstarp or something // like; request several regions. // 2. "quite large": we want to have several such blocks in the region // but not want several pre-allocated regions. // 3. "huge": exact fit, we allocate only one block and do not allow // any other allocations to placed in a region. // Dividing the block sizes in these groups we are trying to balance between // too small regions (that leads to fragmentation) and too large ones (that // leads to excessive address space consumption). If a region is "too // large", allocate only one, to prevent fragmentation. It supposedly // doesn't hurt performance, because the object requested by user is large. // Bounds for the groups are: const size_t maxBinned = getMaxBinnedSize(); const size_t quiteSmall = maxBinned / 8; const size_t quiteLarge = maxBinned; if (blockSize >= quiteLarge) { // Do not interact with other threads via semaphores, as for exact fit // we can't share regions with them, memory requesting is individual. block = addNewRegion(blockSize, MEMREG_ONE_BLOCK, /*addToBin=*/false); if (!block) return releaseMemInCaches(startModifiedCnt, lockedBinsThreshold, numOfLockedBins); *splittableRet = false; } else { const size_t regSz_sizeBased = alignUp(4*maxRequestedSize, 1024*1024); // Another thread is modifying backend while we can't get the block. // Wait while it leaves and re-do the scan // before trying other ways to extend the backend. if (bkndSync.waitTillBlockReleased(startModifiedCnt) // semaphore is protecting adding more more memory from OS || memExtendingSema.wait()) return (FreeBlock*)VALID_BLOCK_IN_BIN; if (startModifiedCnt != bkndSync.getNumOfMods()) { memExtendingSema.signal(); return (FreeBlock*)VALID_BLOCK_IN_BIN; } if (blockSize < quiteSmall) { // For this size of blocks, add NUM_OF_REG "advance" regions in bin, // and return one as a result. // TODO: add to bin first, because other threads can use them right away. // This must be done carefully, because blocks in bins can be released // in releaseCachesToLimit(). const unsigned NUM_OF_REG = 3; MemRegionType regType = needSlabRegion ? MEMREG_SLAB_BLOCKS : MEMREG_LARGE_BLOCKS; block = addNewRegion(regSz_sizeBased, regType, /*addToBin=*/false); if (block) for (unsigned idx=0; idx<NUM_OF_REG; idx++) if (! addNewRegion(regSz_sizeBased, regType, /*addToBin=*/true)) break; } else { block = addNewRegion(regSz_sizeBased, MEMREG_LARGE_BLOCKS, /*addToBin=*/false); } memExtendingSema.signal(); // no regions found, try to clean cache if (!block || block == (FreeBlock*)VALID_BLOCK_IN_BIN) return releaseMemInCaches(startModifiedCnt, lockedBinsThreshold, numOfLockedBins); // Since a region can hold more than one block it can be split. *splittableRet = true; } // after asking memory from OS, release caches if we above the memory limits releaseCachesToLimit(); return block; } void Backend::releaseCachesToLimit() { if (!memSoftLimit.load(std::memory_order_relaxed) || totalMemSize.load(std::memory_order_relaxed) <= memSoftLimit.load(std::memory_order_relaxed)) { return; } size_t locTotalMemSize, locMemSoftLimit; scanCoalescQ(/*forceCoalescQDrop=*/false); if (extMemPool->softCachesCleanup() && (locTotalMemSize = totalMemSize.load(std::memory_order_acquire)) <= (locMemSoftLimit = memSoftLimit.load(std::memory_order_acquire))) return; // clean global large-object cache, if this is not enough, clean local caches // do this in several tries, because backend fragmentation can prevent // region from releasing for (int cleanLocal = 0; cleanLocal<2; cleanLocal++) while (cleanLocal ? extMemPool->allLocalCaches.cleanup(/*cleanOnlyUnused=*/true) : extMemPool->loc.decreasingCleanup()) if ((locTotalMemSize = totalMemSize.load(std::memory_order_acquire)) <= (locMemSoftLimit = memSoftLimit.load(std::memory_order_acquire))) return; // last chance to match memSoftLimit extMemPool->hardCachesCleanup(); } int Backend::IndexedBins::getMinNonemptyBin(unsigned startBin) const { int p = bitMask.getMinTrue(startBin); return p == -1 ? Backend::freeBinsNum : p; } FreeBlock *Backend::IndexedBins::findBlock(int nativeBin, BackendSync *sync, size_t size, bool needAlignedBlock, bool alignedBin, int *numOfLockedBins) { for (int i=getMinNonemptyBin(nativeBin); i<freeBinsNum; i=getMinNonemptyBin(i+1)) if (FreeBlock *block = getFromBin(i, sync, size, needAlignedBlock, alignedBin, /*wait=*/false, numOfLockedBins)) return block; return NULL; } void Backend::requestBootstrapMem() { if (bootsrapMemDone == bootsrapMemStatus.load(std::memory_order_acquire)) return; MallocMutex::scoped_lock lock( bootsrapMemStatusMutex ); if (bootsrapMemDone == bootsrapMemStatus) return; MALLOC_ASSERT(bootsrapMemNotDone == bootsrapMemStatus, ASSERT_TEXT); bootsrapMemStatus = bootsrapMemInitializing; // request some rather big region during bootstrap in advance // ok to get NULL here, as later we re-do a request with more modest size addNewRegion(2*1024*1024, MEMREG_SLAB_BLOCKS, /*addToBin=*/true); bootsrapMemStatus = bootsrapMemDone; } // try to allocate size Byte block in available bins // needAlignedRes is true if result must be slab-aligned FreeBlock *Backend::genericGetBlock(int num, size_t size, bool needAlignedBlock) { FreeBlock *block = NULL; const size_t totalReqSize = num*size; // no splitting after requesting new region, asks exact size const int nativeBin = sizeToBin(totalReqSize); requestBootstrapMem(); // If we found 2 or less locked bins, it's time to ask more memory from OS. // But nothing can be asked from fixed pool. And we prefer wait, not ask // for more memory, if block is quite large. int lockedBinsThreshold = extMemPool->fixedPool || size>=maxBinned_SmallPage? 0 : 2; // Find maximal requested size limited by getMaxBinnedSize() AtomicUpdate(maxRequestedSize, totalReqSize, MaxRequestComparator(this)); scanCoalescQ(/*forceCoalescQDrop=*/false); bool splittable = true; for (;;) { const intptr_t startModifiedCnt = bkndSync.getNumOfMods(); int numOfLockedBins; do { numOfLockedBins = 0; if (needAlignedBlock) { block = freeSlabAlignedBins.findBlock(nativeBin, &bkndSync, num*size, needAlignedBlock, /*alignedBin=*/true, &numOfLockedBins); if (!block && extMemPool->fixedPool) block = freeLargeBlockBins.findBlock(nativeBin, &bkndSync, num*size, needAlignedBlock, /*alignedBin=*/false, &numOfLockedBins); } else { block = freeLargeBlockBins.findBlock(nativeBin, &bkndSync, num*size, needAlignedBlock, /*alignedBin=*/false, &numOfLockedBins); if (!block && extMemPool->fixedPool) block = freeSlabAlignedBins.findBlock(nativeBin, &bkndSync, num*size, needAlignedBlock, /*alignedBin=*/true, &numOfLockedBins); } } while (!block && numOfLockedBins>lockedBinsThreshold); if (block) break; if (!(scanCoalescQ(/*forceCoalescQDrop=*/true) | extMemPool->softCachesCleanup())) { // bins are not updated, // only remaining possibility is to ask for more memory block = askMemFromOS(totalReqSize, startModifiedCnt, &lockedBinsThreshold, numOfLockedBins, &splittable, needAlignedBlock); if (!block) return NULL; if (block != (FreeBlock*)VALID_BLOCK_IN_BIN) { // size can be increased in askMemFromOS, that's why >= MALLOC_ASSERT(block->sizeTmp >= size, ASSERT_TEXT); break; } // valid block somewhere in bins, let's find it block = NULL; } } MALLOC_ASSERT(block, ASSERT_TEXT); if (splittable) { // At this point we have to be sure that slabAligned attribute describes the right block state block = splitBlock(block, num, size, block->slabAligned, needAlignedBlock); } // matched blockConsumed() from startUseBlock() bkndSync.blockReleased(); return block; } LargeMemoryBlock *Backend::getLargeBlock(size_t size) { LargeMemoryBlock *lmb = (LargeMemoryBlock*)genericGetBlock(1, size, /*needAlignedRes=*/false); if (lmb) { lmb->unalignedSize = size; if (extMemPool->userPool()) extMemPool->lmbList.add(lmb); } return lmb; } BlockI *Backend::getSlabBlock(int num) { BlockI *b = (BlockI*)genericGetBlock(num, slabSize, /*slabAligned=*/true); MALLOC_ASSERT(isAligned(b, slabSize), ASSERT_TEXT); return b; } void Backend::putSlabBlock(BlockI *block) { genericPutBlock((FreeBlock *)block, slabSize, /*slabAligned=*/true); } void *Backend::getBackRefSpace(size_t size, bool *rawMemUsed) { // This block is released only at shutdown, so it can prevent // a entire region releasing when it's received from the backend, // so prefer getRawMemory using. if (void *ret = getRawMemory(size, REGULAR)) { *rawMemUsed = true; return ret; } void *ret = genericGetBlock(1, size, /*needAlignedRes=*/false); if (ret) *rawMemUsed = false; return ret; } void Backend::putBackRefSpace(void *b, size_t size, bool rawMemUsed) { if (rawMemUsed) freeRawMemory(b, size); // ignore not raw mem, as it released on region releasing } void Backend::removeBlockFromBin(FreeBlock *fBlock) { if (fBlock->myBin != Backend::NO_BIN) { if (fBlock->slabAligned) freeSlabAlignedBins.lockRemoveBlock(fBlock->myBin, fBlock); else freeLargeBlockBins.lockRemoveBlock(fBlock->myBin, fBlock); } } void Backend::genericPutBlock(FreeBlock *fBlock, size_t blockSz, bool slabAligned) { bkndSync.blockConsumed(); coalescAndPut(fBlock, blockSz, slabAligned); bkndSync.blockReleased(); } void AllLargeBlocksList::add(LargeMemoryBlock *lmb) { MallocMutex::scoped_lock scoped_cs(largeObjLock); lmb->gPrev = NULL; lmb->gNext = loHead; if (lmb->gNext) lmb->gNext->gPrev = lmb; loHead = lmb; } void AllLargeBlocksList::remove(LargeMemoryBlock *lmb) { MallocMutex::scoped_lock scoped_cs(largeObjLock); if (loHead == lmb) loHead = lmb->gNext; if (lmb->gNext) lmb->gNext->gPrev = lmb->gPrev; if (lmb->gPrev) lmb->gPrev->gNext = lmb->gNext; } void Backend::putLargeBlock(LargeMemoryBlock *lmb) { if (extMemPool->userPool()) extMemPool->lmbList.remove(lmb); genericPutBlock((FreeBlock *)lmb, lmb->unalignedSize, false); } void Backend::returnLargeObject(LargeMemoryBlock *lmb) { removeBackRef(lmb->backRefIdx); putLargeBlock(lmb); STAT_increment(getThreadId(), ThreadCommonCounters, freeLargeObj); } #if BACKEND_HAS_MREMAP void *Backend::remap(void *ptr, size_t oldSize, size_t newSize, size_t alignment) { // no remap for user pools and for object too small that living in bins if (inUserPool() || min(oldSize, newSize)<maxBinned_SmallPage // during remap, can't guarantee alignment more strict than current or // more strict than page alignment || !isAligned(ptr, alignment) || alignment>extMemPool->granularity) return NULL; const LargeMemoryBlock* lmbOld = ((LargeObjectHdr *)ptr - 1)->memoryBlock; const size_t oldUnalignedSize = lmbOld->unalignedSize; FreeBlock *oldFBlock = (FreeBlock *)lmbOld; FreeBlock *right = oldFBlock->rightNeig(oldUnalignedSize); // in every region only one block can have LAST_REGION_BLOCK on right, // so don't need no synchronization if (!right->isLastRegionBlock()) return NULL; MemRegion *oldRegion = static_cast<LastFreeBlock*>(right)->memRegion; MALLOC_ASSERT( oldRegion < ptr, ASSERT_TEXT ); const size_t oldRegionSize = oldRegion->allocSz; if (oldRegion->type != MEMREG_ONE_BLOCK) return NULL; // we are not single in the region const size_t userOffset = (uintptr_t)ptr - (uintptr_t)oldRegion; const size_t alignedSize = LargeObjectCache::alignToBin(newSize + userOffset); const size_t requestSize = alignUp(sizeof(MemRegion) + alignedSize + sizeof(LastFreeBlock), extMemPool->granularity); if (requestSize < alignedSize) // is wrapped around? return NULL; regionList.remove(oldRegion); // The deallocation should be registered in address range before mremap to // prevent a race condition with allocation on another thread. // (OS can reuse the memory and registerAlloc will be missed on another thread) usedAddrRange.registerFree((uintptr_t)oldRegion, (uintptr_t)oldRegion + oldRegionSize); void *ret = mremap(oldRegion, oldRegion->allocSz, requestSize, MREMAP_MAYMOVE); if (MAP_FAILED == ret) { // can't remap, revert and leave regionList.add(oldRegion); usedAddrRange.registerAlloc((uintptr_t)oldRegion, (uintptr_t)oldRegion + oldRegionSize); return NULL; } MemRegion *region = (MemRegion*)ret; MALLOC_ASSERT(region->type == MEMREG_ONE_BLOCK, ASSERT_TEXT); region->allocSz = requestSize; region->blockSz = alignedSize; FreeBlock *fBlock = (FreeBlock *)alignUp((uintptr_t)region + sizeof(MemRegion), largeObjectAlignment); regionList.add(region); startUseBlock(region, fBlock, /*addToBin=*/false); MALLOC_ASSERT(fBlock->sizeTmp == region->blockSz, ASSERT_TEXT); // matched blockConsumed() in startUseBlock(). // TODO: get rid of useless pair blockConsumed()/blockReleased() bkndSync.blockReleased(); // object must start at same offset from region's start void *object = (void*)((uintptr_t)region + userOffset); MALLOC_ASSERT(isAligned(object, alignment), ASSERT_TEXT); LargeObjectHdr *header = (LargeObjectHdr*)object - 1; setBackRef(header->backRefIdx, header); LargeMemoryBlock *lmb = (LargeMemoryBlock*)fBlock; lmb->unalignedSize = region->blockSz; lmb->objectSize = newSize; lmb->backRefIdx = header->backRefIdx; header->memoryBlock = lmb; MALLOC_ASSERT((uintptr_t)lmb + lmb->unalignedSize >= (uintptr_t)object + lmb->objectSize, "An object must fit to the block."); usedAddrRange.registerAlloc((uintptr_t)region, (uintptr_t)region + requestSize); totalMemSize.fetch_add(region->allocSz - oldRegionSize); return object; } #endif /* BACKEND_HAS_MREMAP */ void Backend::releaseRegion(MemRegion *memRegion) { regionList.remove(memRegion); freeRawMem(memRegion, memRegion->allocSz); } // coalesce fBlock with its neighborhood FreeBlock *Backend::doCoalesc(FreeBlock *fBlock, MemRegion **mRegion) { FreeBlock *resBlock = fBlock; size_t resSize = fBlock->sizeTmp; MemRegion *memRegion = NULL; fBlock->markCoalescing(resSize); resBlock->blockInBin = false; // coalescing with left neighbor size_t leftSz = fBlock->trySetLeftUsed(GuardedSize::COAL_BLOCK); if (leftSz != GuardedSize::LOCKED) { if (leftSz == GuardedSize::COAL_BLOCK) { coalescQ.putBlock(fBlock); return NULL; } else { FreeBlock *left = fBlock->leftNeig(leftSz); size_t lSz = left->trySetMeUsed(GuardedSize::COAL_BLOCK); if (lSz <= GuardedSize::MAX_LOCKED_VAL) { fBlock->setLeftFree(leftSz); // rollback coalescQ.putBlock(fBlock); return NULL; } else { MALLOC_ASSERT(lSz == leftSz, "Invalid header"); left->blockInBin = true; resBlock = left; resSize += leftSz; resBlock->sizeTmp = resSize; } } } // coalescing with right neighbor FreeBlock *right = fBlock->rightNeig(fBlock->sizeTmp); size_t rightSz = right->trySetMeUsed(GuardedSize::COAL_BLOCK); if (rightSz != GuardedSize::LOCKED) { // LastFreeBlock is on the right side if (GuardedSize::LAST_REGION_BLOCK == rightSz) { right->setMeFree(GuardedSize::LAST_REGION_BLOCK); memRegion = static_cast<LastFreeBlock*>(right)->memRegion; } else if (GuardedSize::COAL_BLOCK == rightSz) { if (resBlock->blockInBin) { resBlock->blockInBin = false; removeBlockFromBin(resBlock); } coalescQ.putBlock(resBlock); return NULL; } else { size_t rSz = right->rightNeig(rightSz)-> trySetLeftUsed(GuardedSize::COAL_BLOCK); if (rSz <= GuardedSize::MAX_LOCKED_VAL) { right->setMeFree(rightSz); // rollback if (resBlock->blockInBin) { resBlock->blockInBin = false; removeBlockFromBin(resBlock); } coalescQ.putBlock(resBlock); return NULL; } else { MALLOC_ASSERT(rSz == rightSz, "Invalid header"); removeBlockFromBin(right); resSize += rightSz; // Is LastFreeBlock on the right side of right? FreeBlock *nextRight = right->rightNeig(rightSz); size_t nextRightSz = nextRight-> trySetMeUsed(GuardedSize::COAL_BLOCK); if (nextRightSz > GuardedSize::MAX_LOCKED_VAL) { if (nextRightSz == GuardedSize::LAST_REGION_BLOCK) memRegion = static_cast<LastFreeBlock*>(nextRight)->memRegion; nextRight->setMeFree(nextRightSz); } } } } if (memRegion) { MALLOC_ASSERT((uintptr_t)memRegion + memRegion->allocSz >= (uintptr_t)right + sizeof(LastFreeBlock), ASSERT_TEXT); MALLOC_ASSERT((uintptr_t)memRegion < (uintptr_t)resBlock, ASSERT_TEXT); *mRegion = memRegion; } else *mRegion = NULL; resBlock->sizeTmp = resSize; return resBlock; } bool Backend::coalescAndPutList(FreeBlock *list, bool forceCoalescQDrop, bool reportBlocksProcessed) { bool regionReleased = false; for (FreeBlock *helper; list; list = helper, // matches block enqueue in CoalRequestQ::putBlock() reportBlocksProcessed? coalescQ.blockWasProcessed() : (void)0) { MemRegion *memRegion; bool addToTail = false; helper = list->nextToFree; FreeBlock *toRet = doCoalesc(list, &memRegion); if (!toRet) continue; if (memRegion && memRegion->blockSz == toRet->sizeTmp && !extMemPool->fixedPool) { if (extMemPool->regionsAreReleaseable()) { // release the region, because there is no used blocks in it if (toRet->blockInBin) removeBlockFromBin(toRet); releaseRegion(memRegion); regionReleased = true; continue; } else // add block from empty region to end of bin, addToTail = true; // preserving for exact fit } size_t currSz = toRet->sizeTmp; int bin = sizeToBin(currSz); bool toAligned = extMemPool->fixedPool ? toAlignedBin(toRet, currSz) : toRet->slabAligned; bool needAddToBin = true; if (toRet->blockInBin) { // Does it stay in same bin? if (toRet->myBin == bin && toRet->slabAligned == toAligned) needAddToBin = false; else { toRet->blockInBin = false; removeBlockFromBin(toRet); } } // Does not stay in same bin, or bin-less; add it if (needAddToBin) { toRet->prev = toRet->next = toRet->nextToFree = NULL; toRet->myBin = NO_BIN; toRet->slabAligned = toAligned; // If the block is too small to fit in any bin, keep it bin-less. // It's not a leak because the block later can be coalesced. if (currSz >= minBinnedSize) { toRet->sizeTmp = currSz; IndexedBins *target = toRet->slabAligned ? &freeSlabAlignedBins : &freeLargeBlockBins; if (forceCoalescQDrop) { target->addBlock(bin, toRet, toRet->sizeTmp, addToTail); } else if (!target->tryAddBlock(bin, toRet, addToTail)) { coalescQ.putBlock(toRet); continue; } } toRet->sizeTmp = 0; } // Free (possibly coalesced) free block. // Adding to bin must be done before this point, // because after a block is free it can be coalesced, and // using its pointer became unsafe. // Remember that coalescing is not done under any global lock. toRet->setMeFree(currSz); toRet->rightNeig(currSz)->setLeftFree(currSz); } return regionReleased; } // Coalesce fBlock and add it back to a bin; // processing delayed coalescing requests. void Backend::coalescAndPut(FreeBlock *fBlock, size_t blockSz, bool slabAligned) { fBlock->sizeTmp = blockSz; fBlock->nextToFree = NULL; fBlock->slabAligned = slabAligned; coalescAndPutList(fBlock, /*forceCoalescQDrop=*/false, /*reportBlocksProcessed=*/false); } bool Backend::scanCoalescQ(bool forceCoalescQDrop) { FreeBlock *currCoalescList = coalescQ.getAll(); if (currCoalescList) // reportBlocksProcessed=true informs that the blocks leave coalescQ, // matches blockConsumed() from CoalRequestQ::putBlock() coalescAndPutList(currCoalescList, forceCoalescQDrop, /*reportBlocksProcessed=*/true); // returns status of coalescQ.getAll(), as an indication of possible changes in backend // TODO: coalescAndPutList() may report is some new free blocks became available or not return currCoalescList; } FreeBlock *Backend::findBlockInRegion(MemRegion *region, size_t exactBlockSize) { FreeBlock *fBlock; size_t blockSz; uintptr_t fBlockEnd, lastFreeBlock = (uintptr_t)region + region->allocSz - sizeof(LastFreeBlock); static_assert(sizeof(LastFreeBlock) % sizeof(uintptr_t) == 0, "Atomic applied on LastFreeBlock, and we put it at the end of region, that" " is uintptr_t-aligned, so no unaligned atomic operations are possible."); // right bound is slab-aligned, keep LastFreeBlock after it if (region->type == MEMREG_SLAB_BLOCKS) { fBlock = (FreeBlock *)alignUp((uintptr_t)region + sizeof(MemRegion), sizeof(uintptr_t)); fBlockEnd = alignDown(lastFreeBlock, slabSize); } else { fBlock = (FreeBlock *)alignUp((uintptr_t)region + sizeof(MemRegion), largeObjectAlignment); fBlockEnd = (uintptr_t)fBlock + exactBlockSize; MALLOC_ASSERT(fBlockEnd <= lastFreeBlock, ASSERT_TEXT); } if (fBlockEnd <= (uintptr_t)fBlock) return NULL; // allocSz is too small blockSz = fBlockEnd - (uintptr_t)fBlock; // TODO: extend getSlabBlock to support degradation, i.e. getting less blocks // then requested, and then relax this check // (now all or nothing is implemented, check according to this) if (blockSz < numOfSlabAllocOnMiss*slabSize) return NULL; region->blockSz = blockSz; return fBlock; } // startUseBlock may add the free block to a bin, the block can be used and // even released after this, so the region must be added to regionList already void Backend::startUseBlock(MemRegion *region, FreeBlock *fBlock, bool addToBin) { size_t blockSz = region->blockSz; fBlock->initHeader(); fBlock->setMeFree(blockSz); LastFreeBlock *lastBl = static_cast<LastFreeBlock*>(fBlock->rightNeig(blockSz)); // to not get unaligned atomics during LastFreeBlock access MALLOC_ASSERT(isAligned(lastBl, sizeof(uintptr_t)), NULL); lastBl->initHeader(); lastBl->setMeFree(GuardedSize::LAST_REGION_BLOCK); lastBl->setLeftFree(blockSz); lastBl->myBin = NO_BIN; lastBl->memRegion = region; if (addToBin) { unsigned targetBin = sizeToBin(blockSz); // during adding advance regions, register bin for a largest block in region advRegBins.registerBin(targetBin); if (region->type == MEMREG_SLAB_BLOCKS) { fBlock->slabAligned = true; freeSlabAlignedBins.addBlock(targetBin, fBlock, blockSz, /*addToTail=*/false); } else { fBlock->slabAligned = false; freeLargeBlockBins.addBlock(targetBin, fBlock, blockSz, /*addToTail=*/false); } } else { // to match with blockReleased() in genericGetBlock bkndSync.blockConsumed(); // Understand our alignment for correct splitBlock operation fBlock->slabAligned = region->type == MEMREG_SLAB_BLOCKS ? true : false; fBlock->sizeTmp = fBlock->tryLockBlock(); MALLOC_ASSERT(fBlock->sizeTmp >= FreeBlock::minBlockSize, "Locking must be successful"); } } void MemRegionList::add(MemRegion *r) { r->prev = NULL; MallocMutex::scoped_lock lock(regionListLock); r->next = head; head = r; if (head->next) head->next->prev = head; } void MemRegionList::remove(MemRegion *r) { MallocMutex::scoped_lock lock(regionListLock); if (head == r) head = head->next; if (r->next) r->next->prev = r->prev; if (r->prev) r->prev->next = r->next; } #if __TBB_MALLOC_BACKEND_STAT int MemRegionList::reportStat(FILE *f) { int regNum = 0; MallocMutex::scoped_lock lock(regionListLock); for (MemRegion *curr = head; curr; curr = curr->next) { fprintf(f, "%p: max block %lu B, ", curr, curr->blockSz); regNum++; } return regNum; } #endif FreeBlock *Backend::addNewRegion(size_t size, MemRegionType memRegType, bool addToBin) { static_assert(sizeof(BlockMutexes) <= sizeof(BlockI), "Header must be not overwritten in used blocks"); MALLOC_ASSERT(FreeBlock::minBlockSize > GuardedSize::MAX_SPEC_VAL, "Block length must not conflict with special values of GuardedSize"); // If the region is not "for slabs" we should reserve some space for // a region header, the worst case alignment and the last block mark. const size_t requestSize = memRegType == MEMREG_SLAB_BLOCKS ? size : size + sizeof(MemRegion) + largeObjectAlignment + FreeBlock::minBlockSize + sizeof(LastFreeBlock); size_t rawSize = requestSize; MemRegion *region = (MemRegion*)allocRawMem(rawSize); if (!region) { MALLOC_ASSERT(rawSize==requestSize, "getRawMem has not allocated memory but changed the allocated size."); return NULL; } if (rawSize < sizeof(MemRegion)) { if (!extMemPool->fixedPool) freeRawMem(region, rawSize); return NULL; } region->type = memRegType; region->allocSz = rawSize; FreeBlock *fBlock = findBlockInRegion(region, size); if (!fBlock) { if (!extMemPool->fixedPool) freeRawMem(region, rawSize); return NULL; } regionList.add(region); startUseBlock(region, fBlock, addToBin); bkndSync.binsModified(); return addToBin? (FreeBlock*)VALID_BLOCK_IN_BIN : fBlock; } void Backend::init(ExtMemoryPool *extMemoryPool) { extMemPool = extMemoryPool; usedAddrRange.init(); coalescQ.init(&bkndSync); bkndSync.init(this); } void Backend::reset() { MALLOC_ASSERT(extMemPool->userPool(), "Only user pool can be reset."); // no active threads are allowed in backend while reset() called verify(); freeLargeBlockBins.reset(); freeSlabAlignedBins.reset(); advRegBins.reset(); for (MemRegion *curr = regionList.head; curr; curr = curr->next) { FreeBlock *fBlock = findBlockInRegion(curr, curr->blockSz); MALLOC_ASSERT(fBlock, "A memory region unexpectedly got smaller"); startUseBlock(curr, fBlock, /*addToBin=*/true); } } bool Backend::destroy() { bool noError = true; // no active threads are allowed in backend while destroy() called verify(); if (!inUserPool()) { freeLargeBlockBins.reset(); freeSlabAlignedBins.reset(); } while (regionList.head) { MemRegion *helper = regionList.head->next; noError &= freeRawMem(regionList.head, regionList.head->allocSz); regionList.head = helper; } return noError; } bool Backend::clean() { scanCoalescQ(/*forceCoalescQDrop=*/false); bool res = false; // We can have several blocks occupying a whole region, // because such regions are added in advance (see askMemFromOS() and reset()), // and never used. Release them all. for (int i = advRegBins.getMinUsedBin(0); i != -1; i = advRegBins.getMinUsedBin(i+1)) { if (i == freeSlabAlignedBins.getMinNonemptyBin(i)) res |= freeSlabAlignedBins.tryReleaseRegions(i, this); if (i == freeLargeBlockBins.getMinNonemptyBin(i)) res |= freeLargeBlockBins.tryReleaseRegions(i, this); } return res; } void Backend::IndexedBins::verify() { #if MALLOC_DEBUG for (int i=0; i<freeBinsNum; i++) { for (FreeBlock *fb = freeBins[i].head.load(std::memory_order_relaxed); fb; fb=fb->next) { uintptr_t mySz = fb->myL.value; MALLOC_ASSERT(mySz>GuardedSize::MAX_SPEC_VAL, ASSERT_TEXT); FreeBlock *right = (FreeBlock*)((uintptr_t)fb + mySz); suppress_unused_warning(right); MALLOC_ASSERT(right->myL.value<=GuardedSize::MAX_SPEC_VAL, ASSERT_TEXT); MALLOC_ASSERT(right->leftL.value==mySz, ASSERT_TEXT); MALLOC_ASSERT(fb->leftL.value<=GuardedSize::MAX_SPEC_VAL, ASSERT_TEXT); } } #endif } // For correct operation, it must be called when no other threads // is changing backend. void Backend::verify() { #if MALLOC_DEBUG scanCoalescQ(/*forceCoalescQDrop=*/false); #endif // MALLOC_DEBUG freeLargeBlockBins.verify(); freeSlabAlignedBins.verify(); } #if __TBB_MALLOC_BACKEND_STAT size_t Backend::Bin::countFreeBlocks() { size_t cnt = 0; { MallocMutex::scoped_lock lock(tLock); for (FreeBlock *fb = head; fb; fb = fb->next) cnt++; } return cnt; } size_t Backend::Bin::reportFreeBlocks(FILE *f) { size_t totalSz = 0; MallocMutex::scoped_lock lock(tLock); for (FreeBlock *fb = head; fb; fb = fb->next) { size_t sz = fb->tryLockBlock(); fb->setMeFree(sz); fprintf(f, " [%p;%p]", fb, (void*)((uintptr_t)fb+sz)); totalSz += sz; } return totalSz; } void Backend::IndexedBins::reportStat(FILE *f) { size_t totalSize = 0; for (int i=0; i<Backend::freeBinsNum; i++) if (size_t cnt = freeBins[i].countFreeBlocks()) { totalSize += freeBins[i].reportFreeBlocks(f); fprintf(f, " %d:%lu, ", i, cnt); } fprintf(f, "\ttotal size %lu KB", totalSize/1024); } void Backend::reportStat(FILE *f) { scanCoalescQ(/*forceCoalescQDrop=*/false); fprintf(f, "\n regions:\n"); int regNum = regionList.reportStat(f); fprintf(f, "\n%d regions, %lu KB in all regions\n free bins:\nlarge bins: ", regNum, totalMemSize/1024); freeLargeBlockBins.reportStat(f); fprintf(f, "\naligned bins: "); freeSlabAlignedBins.reportStat(f); fprintf(f, "\n"); } #endif // __TBB_MALLOC_BACKEND_STAT } } // namespaces
variar/klogg
3rdparty/onetbb/src/tbbmalloc/backend.cpp
C++
gpl-3.0
57,246
<?php include_once dirname(__FILE__)."/SQL_Functions.php"; $event_name = $_GET["event_name"]; $day = $_GET["day"]; $start_time = $_GET["start_time"]; $end_time = $_GET["end_time"]; $return_array = Array("success" => true); #first we validate the inputs, making sure they are there. Also, make sure they are within range if (empty($event_name)){ $return_array["success"]=false; $error_message = "VALUEERROR: event_name paramiter not passed"; $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } if (empty($day)){ $return_array["success"]=false; $error_message = "VALUEERROR: day paramiter not passed"; $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } else if (($day > 5) || ($start_time < 0)){ $return_array["success"]=false; $error_message = "VALUEERROR: day is $day value should be >0 and <=5"; $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } if (empty($start_time)){ $return_array["success"]=false; $error_message = "VALUEERROR: start_time paramiter not passed"; $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } else if (($start_time > 1440) || ($start_time < 0)){ $return_array["success"]=false; $error_message = "VALUEERROR: start_time is $start_time value should be >0 and <=1440"; $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } if (empty($end_time)){ $return_array["success"]=false; $error_message = "VALUEERROR: day paramiter not passed"; $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } else if (($end_time > 1440) || ($end_time < 0)){ $return_array["success"]=false; $error_message = "VALUEERROR: end_time is $end_time value should be >0 and <=1440"; $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } if ($start_time >= $end_time){ $return_array["success"]=false; $error_message = "VALUEERROR: start_time:$start_time before end_time:$end_time "; $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } if ($return_array["success"]){ if(isset($_COOKIE['SID'])){ session_id($_COOKIE['SID']); session_start(); if(isset($_SESSION['Username'])){ $username = $_SESSION['Username']; $result = SaveEvent($event_name,$start_time,$end_time,$day,$username); if (!$result){ $return_array["success"]=false; $error_message = "SQLERROR: Error inserting into database -- ".mysql_error(); $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } } else { $return_array["success"]=false; $error_message = "SESSIONERROR: Session Expired"; $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } } else { $return_array["success"]=false; $error_message = "SESSIONERROR: Login Required"; $return_array["error"]=(empty($return_array["error"]) ? $error_message : $return_array["error"] .';'. $error_message); } } echo json_encode($return_array); ?>
KevinAnthony/SeniorProject
json/SaveEvent.php
PHP
gpl-3.0
3,644
<?php // Example 26-5: signup.php require_once 'header.php'; echo <<<_END <script> function checkUser(user) { if (user.value == '') { O('info').innerHTML = '' return } params = "user=" + user.value request = new ajaxRequest() request.open("POST", "checkuser.php", true) request.setRequestHeader("Content-type", "application/x-www-form-urlencoded") request.setRequestHeader("Content-length", params.length) request.setRequestHeader("Connection", "close") request.onreadystatechange = function() { if (this.readyState == 4) if (this.status == 200) if (this.responseText != null) O('info').innerHTML = this.responseText } request.send(params) } function ajaxRequest() { try { var request = new XMLHttpRequest() } catch(e1) { try { request = new ActiveXObject("Msxml2.XMLHTTP") } catch(e2) { try { request = new ActiveXObject("Microsoft.XMLHTTP") } catch(e3) { request = false } } } return request } </script> <div class='main'><h3>Please enter your details to sign up</h3> _END; $error = $user = $pass = ""; if (isset($_SESSION['user'])) destroySession(); if (isset($_POST['user'])) { $user = sanitizeString($_POST['user']); $pass = sanitizeString($_POST['pass']); if ($user == "" || $pass == "") $error = "Not all fields were entered<br><br>"; else { $result = queryMysql("SELECT * FROM members WHERE user='$user'"); if ($result->num_rows) $error = "That username already exists<br><br>"; else { queryMysql("INSERT INTO members VALUES('$user', '$pass')"); die("<h4>Account created</h4>Please Log in.<br><br>"); } } } echo <<<_END <form method='post' action='signup.php'>$error <span class='fieldname'>Username</span> <input type='text' maxlength='16' name='user' value='$user' onBlur='checkUser(this)'><span id='info'></span><br> <span class='fieldname'>Password</span> <input type='text' maxlength='16' name='pass' value='$pass'><br> _END; ?> <span class='fieldname'>&nbsp;</span> <input type='submit' value='Sign up'> </form></div><br> </body> </html>
JSHai/PHPWebsite
signup.php
PHP
gpl-3.0
2,349
module Destroy class Page # Destroy the object only def destroy!(page:) page.destroy! end # There are no additional cascades for Pages, # so destroys the object only def cascade!(page:) ActiveRecord::Base.transaction do DestroyPageItemAssociations.call(page_id: page.id) page.destroy! end end end end
leftees/honeycomb
app/services/destroy/page.rb
Ruby
gpl-3.0
368
// ********************************************************************************** // Websocket backend for the Raspberry Pi IoT Framework // ********************************************************************************** // Modified from the Moteino IoT Framework - http://lowpowerlab.com/gateway // By Felix Rusu, Low Power Lab LLC (2015), http://lowpowerlab.com/contact // ********************************************************************************** // Based on Node.js, socket.io, NeDB // This is a work in progress and is released without any warranties expressed or implied. // Please read the details below. // Also ensure you change the settings in this file to match your hardware and email settings etc. // ********************************************************************************** // NeDB is Node Embedded Database - a persistent database for Node.js, with no dependency // Specs and documentation at: https://github.com/louischatriot/nedb // // Under the hood, NeDB's persistence uses an append-only format, meaning that all updates // and deletes actually result in lines added at the end of the datafile. The reason for // this is that disk space is very cheap and appends are much faster than rewrites since // they don't do a seek. The database is automatically compacted (i.e. put back in the // one-line-per-document format) everytime your application restarts. // // This script is configured to compact the database every 24 hours since time of start. // ******************************************************************************************** // Copyright Brian Ladner // ******************************************************************************************** // LICENSE // ******************************************************************************************** // This source code is released under GPL 3.0 with the following ammendments: // You are free to use, copy, distribute and transmit this Software for non-commercial purposes. // - You cannot sell this Software for profit while it was released freely to you by Low Power Lab LLC. // - You may freely use this Software commercially only if you also release it freely, // without selling this Software portion of your system for profit to the end user or entity. // If this Software runs on a hardware system that you sell for profit, you must not charge // any fees for this Software, either upfront or for retainer/support purposes // - If you want to resell this Software or a derivative you must get permission from Low Power Lab LLC. // - You must maintain the attribution and copyright notices in any forks, redistributions and // include the provided links back to the original location where this work is published, // even if your fork or redistribution was initially an N-th tier fork of this original release. // - You must release any derivative work under the same terms and license included here. // - This Software is released without any warranty expressed or implied, and Low Power Lab LLC // will accept no liability for your use of the Software (except to the extent such liability // cannot be excluded as required by law). // - Low Power Lab LLC reserves the right to adjust or replace this license with one // that is more appropriate at any time without any prior consent. // Otherwise all other non-conflicting and overlapping terms of the GPL terms below will apply. // ******************************************************************************************** // This program is free software; you can redistribute it and/or modify it under the terms // of the GNU General Public License as published by the Free Software Foundation; // either version 3 of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with this program. // If not license can be viewed at: http://www.gnu.org/licenses/gpl-3.0.txt // // Please maintain this license information along with authorship // and copyright notices in any redistribution of this code // ********************************************************************************** //var io = require('socket.io').listen(8080); var io = require('socket.io').listen(8888); var Datastore = require('nedb'); var globalFunctions = require('./globals'); var alerts = require('./alerts'); var clients = require('./clients'); var logger = require("./logger"); var cfg = require('./config.default'); var alertsDef = new alerts(); var clientsDef = new clients(); // db to keep all devices and changes var db = new Datastore({ filename: __dirname + '/databases/DBclients.db', autoload: true }); db.persistence.setAutocompactionInterval(86400000); //daily // authorize handshake - make sure the request is coming from nginx, // not from the outside world. If you comment out this section, you // will be able to hit this socket directly at the port it's running // at, from anywhere! This was tested on Socket.IO v1.2.1 and will // not work on older versions io.use(function(socket, next) { var handshakeData = socket.request; var remoteAddress = handshakeData.connection.remoteAddress; var remotePort = handshakeData.connection.remotePort; logger.info("AUTHORIZING CONNECTION FROM " + remoteAddress + ":" + remotePort); if (remoteAddress == "localhost" || remoteAddress == "127.0.0.1") { logger.info('IDENTITY ACCEPTED: from local host'); next(); } else { var remote_add = remoteAddress.split(".",3); var compare_str = cfg.locnet.start.split(".",3); if (remote_add[0] == compare_str[0] && remote_add[1] == compare_str[1] && remote_add[2] == compare_str[2]) { logger.info('IDENTITY ACCEPTED: from local network'); next(); } else { logger.error('REJECTED IDENTITY, not coming from local network'); next(new Error('REJECTED IDENTITY, not coming from local network')); } } }); io.on('connection', function (socket) { logger.info("Socket connected!"); socket.emit('ALERTSDEF', alertsDef.availableAlerts); socket.emit('CLIENTSDEF', clientsDef); db.find({ _id : { $exists: true } }, function (err, entries) { io.emit('UPDATENODES', entries); }); socket.on('SEND_DATA', function (deviceData) { logger.info("Updating node info for node: " + deviceData.name); db.find({ _id : deviceData.deviceID }, function (err, entries) { var existingNode = new Object(); if (entries.length == 1) existingNode = entries[0]; existingNode._id = deviceData.deviceID; //existingNode.rssi = deviceData.signalStrength; //update signal strength we last heard from this node, regardless of any matches existingNode.type = deviceData.type; existingNode.label = deviceData.name; existingNode.Status = deviceData.Status; existingNode.lastStateChange = deviceData.lastStateChange; existingNode.updated = new Date().getTime(); //update timestamp we last heard from this node, regardless of any matches // set up existing alert schedules if (existingNode.alerts) { for (var alertKey in existingNode.alerts) { if (existingNode.alerts[alertKey].alertStatus) { if (existingNode.Status == existingNode.alerts[alertKey].clientStatus) { addSchedule(existingNode, alertKey); } else { removeSchedule(existingNode._id, alertKey); } } } } // add entry into database if (entries.length == 0) { db.insert(existingNode); logger.info(' [' + existingNode._id + '] DB-Insert new _id:' + id); } else { db.update({_id:existingNode._id},{$set:existingNode},{}, function (err,numReplaced) { logger.info(' [' + existingNode._id + '] DB-Updates:' + numReplaced); }); } io.emit('LOG', existingNode); io.emit('UPDATENODE', existingNode); alertsDef.handleNodeAlerts(existingNode); }); }); socket.on('CLIENT_INFO', function (deviceData) { logger.info("Updating client info for node: " + deviceData.nodeID); db.find({ _id : deviceData.nodeID }, function (err, entries) { if (entries.length == 1) { var existingNode = entries[0]; existingNode.infoUpdate = deviceData.lastUpdate||undefined; existingNode.rssi = deviceData.wifi||undefined; existingNode.uptime = deviceData.uptime||undefined; existingNode.cpuTemp = deviceData.cpuTemp||undefined; existingNode.temperature = deviceData.temperature||undefined; existingNode.humidity = deviceData.humidity||undefined; existingNode.photo = deviceData.photo||undefined; db.update({_id:deviceData.nodeID},{$set:existingNode},{}, function (err,numReplaced) { //logger.info(' [' + deviceData.nodeID + '] CLIENT_INFO records replaced:' + numReplaced); }); io.emit('UPDATENODE', existingNode); } }); }); socket.on('CONSOLE', function (msg) { logger.info(msg); }); socket.on('UPDATE_DB_ENTRY', function (node) { db.find({ _id : node._id }, function (err, entries) { if (entries.length == 1) { var dbNode = entries[0]; dbNode.type = node.type||undefined; dbNode.label = node.label||undefined; dbNode.descr = node.descr||undefined; dbNode.hidden = (node.hidden == 1 ? 1 : undefined); db.update({ _id: dbNode._id }, { $set : dbNode}, {}, function (err, numReplaced) { logger.info('UPDATE_DB_ENTRY records replaced:' + numReplaced); }); io.emit('UPDATENODE', dbNode); //post it back to all clients to confirm UI changes logger.debug("UPDATE DB ENTRY found docs:" + entries.length); } }); }); socket.on('EDITNODEALERT', function (nodeId, alertKey, newAlert) { logger.debug('**** EDITNODEALERT **** key:' + alertKey); db.find({ _id : nodeId }, function (err, entries) { if (entries.length == 1) { var dbNode = entries[0]; if (newAlert == null) { if (dbNode.alerts[alertKey]) delete dbNode.alerts[alertKey]; } else { if (!dbNode.alerts) { dbNode.alerts = {}; } dbNode.alerts[alertKey] = newAlert; } db.update({ _id: dbNode._id }, { $set : dbNode}, {}, function (err, numReplaced) { logger.debug('DB alert Updated:' + numReplaced); }); if (dbNode.alerts[alertKey] && dbNode.alerts[alertKey].alertStatus) { addSchedule(dbNode, alertKey); } else { removeSchedule(dbNode._id, alertKey); } io.emit('UPDATENODE', dbNode); //post it back to all clients to confirm UI changes } }); }); socket.on('NODEACTION', function (node) { if (node.nodeId && node.action) { logger.info('NODEACTION sent: ' + JSON.stringify(node)); io.emit('ACTION', node); } }); socket.on('DELETENODE', function (nodeId) { db.remove({ _id : nodeId }, function (err, removedCount) { logger.info('DELETED entries: ' + removedCount); db.find({ _id : { $exists: true } }, function (err, entries) { io.emit('UPDATENODES', entries); }); }); removeSchedule(nodeId, null); }); socket.on('SCHEDULE', function () { logger.info("Scheduled Alerts: " + scheduledAlerts); //io.emit('LOG', scheduledAlerts); }); }); // ************************************ // ********** SCHEDULE SETUP ********** // ************************************ //keep track of scheduler based events - these need to be kept in sych with the UI //if UI removes an event, it needs to be cancelled from here as well; // if UI adds a scheduled event it needs to be scheduled and added here also scheduledAlerts = []; //each entry should be defined like this: {nodeId, eventKey, timer} //schedule and register a scheduled type event //function schedule(node, alertKey) { function addSchedule(node, alertKey) { var nextRunTimeout = node.alerts[alertKey].timeout; logger.info('**** ADDING ALERT - nodeId:' + node._id + ' event:' + alertKey + ' to run ' + (nextRunTimeout/60000).toFixed(2) + ' minutes after status is ' + node.alerts[alertKey].clientStatus); var theTimer = setTimeout(function() { var currentTime = new Date().getTime(); logger.debug('Alert Timeout Function for node ' + node._id + ', alert for ' + alertKey); if (node.alerts[alertKey].clientStatus == node.Status && currentTime - node.lastStateChange >= node.alerts[alertKey].timeout) { alertsDef.testAlert(node, alertKey); } removeSchedule(node._id, alertKey); }, nextRunTimeout); //http://www.w3schools.com/jsref/met_win_settimeout.asp scheduledAlerts.push({nodeId:node._id, alertKey:alertKey, timer:theTimer}); //save nodeId, eventKey and timer (needs to be removed if the event is disabled/removed from the UI) } function removeSchedule(nodeId, alertKey) { for (var s in scheduledAlerts) { if (scheduledAlerts[s].nodeId == nodeId) { if (alertKey == null || scheduledAlerts[s].alertKey == alertKey){ logger.info('**** REMOVING SCHEDULED ALERT - nodeId:' + nodeId + 'alert:' + scheduledAlerts[s].alertKey); clearTimeout(scheduledAlerts[s].timer); scheduledAlerts.splice(scheduledAlerts.indexOf(scheduledAlerts[s]), 1) } } } } // ************************************
bjladner/IoPiGateway
gateway.js
JavaScript
gpl-3.0
14,853
/* * This file is part of ARSnova Mobile. * Copyright (C) 2011-2012 Christian Thomas Weber * Copyright (C) 2012-2017 The ARSnova Team * * ARSnova Mobile is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ARSnova Mobile is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ARSnova Mobile. If not, see <http://www.gnu.org/licenses/>. */ Ext.define("ARSnova.controller.Sessions", { extend: 'Ext.app.Controller', requires: [ 'ARSnova.model.Session', 'ARSnova.view.speaker.TabPanel', 'ARSnova.view.feedback.TabPanel', 'ARSnova.view.feedbackQuestions.TabPanel', 'ARSnova.view.user.TabPanel', 'ARSnova.view.user.QuestionPanel' ], launch: function () { /* (Re)join session on Socket.IO connect event */ ARSnova.app.socket.addListener("arsnova/socket/connect", function () { var keyword = sessionStorage.getItem('keyword'); if (keyword) { ARSnova.app.socket.setSession(keyword); ARSnova.app.getController('Feature').lastUpdate = Date.now(); } }); }, login: function (options) { console.debug("Controller: Sessions.login", options); if (options.keyword.length !== 8) { Ext.Msg.alert(Messages.NOTIFICATION, Messages.SESSION_ID_INVALID_LENGTH); sessionStorage.clear(); return; } if (options.keyword.match(/[^0-9]/)) { Ext.Msg.alert(Messages.NOTIFICATION, Messages.SESSION_ID_INVALID); sessionStorage.clear(); return; } /* do login stuff */ var hideLoadMask = ARSnova.app.showLoadIndicator(Messages.LOAD_MASK_LOGIN); var res = ARSnova.app.sessionModel.checkSessionLogin(options.keyword, { success: function (obj) { // check if user is creator of this session if (ARSnova.app.userRole === ARSnova.app.USER_ROLE_SPEAKER) { ARSnova.app.isSessionOwner = true; } else { // check if session is open if (!obj.active) { Ext.Msg.alert(Messages.NOTIFICATION, Messages.SESSION_IS_CLOSED.replace(/###/, obj.name)); sessionStorage.clear(); return; } ARSnova.app.userRole = ARSnova.app.USER_ROLE_STUDENT; ARSnova.app.isSessionOwner = false; } // set local variables localStorage.setItem('sessionId', obj._id); localStorage.setItem('name', obj.name); localStorage.setItem('shortName', obj.shortName); localStorage.setItem('courseId', obj.courseId || ""); localStorage.setItem('courseType', obj.courseType || ""); localStorage.setItem('active', obj.active ? 1 : 0); localStorage.setItem('creationTime', obj.creationTime); sessionStorage.setItem('keyword', obj.keyword); sessionStorage.setItem('features', Ext.encode(obj.features)); ARSnova.app.feedbackModel.lock = obj.feedbackLock; // initialize MathJax ARSnova.app.getController('MathJaxMarkdown').initializeMathJax(); // deactivate several about tabs ARSnova.app.mainTabPanel.tabPanel.deactivateAboutTabs(); ARSnova.app.socket.setSession(obj.keyword); ARSnova.app.getController('Feature').lastUpdate = Date.now(); // start task to update the feedback tab in tabBar ARSnova.app.feedbackModel.on("arsnova/session/feedback/count", ARSnova.app.mainTabPanel.tabPanel.updateFeedbackBadge, ARSnova.app.mainTabPanel.tabPanel); ARSnova.app.feedbackModel.on("arsnova/session/feedback/average", ARSnova.app.mainTabPanel.tabPanel.updateFeedbackIcon, ARSnova.app.mainTabPanel.tabPanel); ARSnova.app.taskManager.start(ARSnova.app.mainTabPanel.tabPanel.config.updateHomeTask); ARSnova.app.mainTabPanel.tabPanel.updateHomeBadge(); ARSnova.app.getController('Sessions').reloadData(false, hideLoadMask); }, notFound: function () { Ext.Msg.alert(Messages.NOTIFICATION, Messages.SESSION_NOT_FOUND); sessionStorage.clear(); hideLoadMask(); }, forbidden: function () { Ext.Msg.alert(Messages.NOTIFICATION, Messages.SESSION_LOCKED); sessionStorage.clear(); hideLoadMask(); }, failure: function () { Ext.Msg.alert(Messages.NOTIFICATION, Messages.CONNECTION_PROBLEM); sessionStorage.clear(); hideLoadMask(); } }); }, logout: function (prevFeatures) { ARSnova.app.socket.setSession(null); ARSnova.app.sessionModel.fireEvent(ARSnova.app.sessionModel.events.sessionLeave); ARSnova.app.loggedInModel.resetActiveUserCount(); // stop task to update the feedback tab in tabBar ARSnova.app.feedbackModel.un("arsnova/session/feedback/count", ARSnova.app.mainTabPanel.tabPanel.updateFeedbackBadge); ARSnova.app.feedbackModel.un("arsnova/session/feedback/average", ARSnova.app.mainTabPanel.tabPanel.updateFeedbackIcon); // online counter badge ARSnova.app.taskManager.stop(ARSnova.app.mainTabPanel.tabPanel.config.updateHomeTask); sessionStorage.removeItem("keyword"); sessionStorage.removeItem("features"); sessionStorage.removeItem("answeredCanceledPiQuestions"); localStorage.removeItem("sessionId"); localStorage.removeItem("name"); localStorage.removeItem("shortName"); localStorage.removeItem("active"); localStorage.removeItem("session"); localStorage.removeItem("courseId"); localStorage.removeItem("courseType"); localStorage.removeItem("creationTime"); ARSnova.app.isSessionOwner = false; /* show about tab panels */ ARSnova.app.mainTabPanel.tabPanel.activateAboutTabs(); ARSnova.app.sessionModel.isLearningProgessOptionsInitialized = false; var tabPanel = ARSnova.app.mainTabPanel.tabPanel; /* show home Panel */ tabPanel.animateActiveItem(tabPanel.homeTabPanel, { type: 'slide', direction: 'right', duration: 700 }); if (ARSnova.app.userRole === ARSnova.app.USER_ROLE_SPEAKER) { /* hide speaker tab panel and destroy listeners */ tabPanel.speakerTabPanel.tab.hide(); tabPanel.speakerTabPanel.inClassPanel.destroyListeners(); /* hide feedback questions panel */ tabPanel.feedbackQuestionsPanel.tab.hide(); } else { /* hide user tab panel and destroy listeners */ if (tabPanel.userTabPanel) { tabPanel.userTabPanel.tab.hide(); tabPanel.userTabPanel.inClassPanel.destroyListeners(); } if (tabPanel.userQuestionsPanel) { tabPanel.userQuestionsPanel.tab.hide(); } if (localStorage.getItem('lastVisitedRole') === ARSnova.app.USER_ROLE_SPEAKER) { localStorage.setItem('role', ARSnova.app.USER_ROLE_SPEAKER); ARSnova.app.userRole = ARSnova.app.USER_ROLE_SPEAKER; localStorage.removeItem('lastVisitedRole'); } } /* hide feedback statistic panel */ tabPanel.feedbackTabPanel.tab.hide(); }, liveClickerSessionReload: function (prevFeatures) { var keyword = sessionStorage.getItem("keyword"); Ext.toast('Session wird neu geladen...', 3000); ARSnova.app.getController('Sessions').logout(prevFeatures); ARSnova.app.getController('Sessions').login({keyword: keyword}); }, reloadData: function (animation, hideLoadMask) { var features = ARSnova.app.getController('Feature').getActiveFeatures(); hideLoadMask = hideLoadMask || Ext.emptyFn; animation = animation || { type: 'slide', duration: 700 }; if (features.liveClicker && ARSnova.app.userRole !== ARSnova.app.USER_ROLE_SPEAKER && localStorage.getItem('lastVisitedRole') !== ARSnova.app.USER_ROLE_SPEAKER) { this.loadClickerSession(animation, hideLoadMask); } else { this.loadDefaultSession(animation, hideLoadMask); } }, loadClickerSession: function (animation, hideLoadMask) { var tabPanel = ARSnova.app.mainTabPanel.tabPanel; /* add feedback statistic panel*/ if (!tabPanel.feedbackTabPanel) { tabPanel.feedbackTabPanel = Ext.create('ARSnova.view.feedback.TabPanel'); tabPanel.insert(3, tabPanel.feedbackTabPanel); } else { tabPanel.feedbackTabPanel.tab.show(); tabPanel.feedbackTabPanel.renew(); } if (tabPanel.userTabPanel) { tabPanel.userTabPanel.tab.hide(); } if (tabPanel.userQuestionsPanel) { tabPanel.userQuestionsPanel.tab.hide(); } if (ARSnova.app.feedbackModel.lock) { tabPanel.feedbackTabPanel.setActiveItem(tabPanel.feedbackTabPanel.statisticPanel); } else { tabPanel.feedbackTabPanel.setActiveItem(tabPanel.feedbackTabPanel.votePanel); } tabPanel.animateActiveItem(tabPanel.feedbackTabPanel, animation); ARSnova.app.getController('Feature').applyFeatures(); ARSnova.app.sessionModel.sessionIsActive = true; hideLoadMask(); }, loadDefaultSession: function (animation, hideLoadMask) { var tabPanel = ARSnova.app.mainTabPanel.tabPanel; var features = ARSnova.app.getController('Feature').getActiveFeatures(); var target; if (ARSnova.app.isSessionOwner && ARSnova.app.userRole === ARSnova.app.USER_ROLE_SPEAKER) { ARSnova.app.sessionModel.fireEvent(ARSnova.app.sessionModel.events.sessionJoinAsSpeaker); /* add speaker in class panel */ if (!tabPanel.speakerTabPanel) { tabPanel.speakerTabPanel = Ext.create('ARSnova.view.speaker.TabPanel'); tabPanel.insert(1, tabPanel.speakerTabPanel); } else { tabPanel.speakerTabPanel.tab.show(); tabPanel.speakerTabPanel.renew(); } /* add feedback statistic panel*/ if (!tabPanel.feedbackTabPanel) { tabPanel.feedbackTabPanel = Ext.create('ARSnova.view.feedback.TabPanel'); tabPanel.insert(3, tabPanel.feedbackTabPanel); } else { tabPanel.feedbackTabPanel.tab.show(); tabPanel.feedbackTabPanel.renew(); } target = features.liveClicker ? tabPanel.feedbackTabPanel : tabPanel.speakerTabPanel; tabPanel.animateActiveItem(target, animation); tabPanel.speakerTabPanel.inClassPanel.registerListeners(); } else { ARSnova.app.sessionModel.fireEvent(ARSnova.app.sessionModel.events.sessionJoinAsStudent); /* add user in class panel */ if (!tabPanel.userTabPanel) { tabPanel.userTabPanel = Ext.create('ARSnova.view.user.TabPanel'); tabPanel.insert(0, tabPanel.userTabPanel); } else { tabPanel.userTabPanel.tab.show(); tabPanel.userTabPanel.renew(); } tabPanel.userTabPanel.inClassPanel.registerListeners(); /* add skill questions panel*/ if (!tabPanel.userQuestionsPanel) { tabPanel.userQuestionsPanel = Ext.create('ARSnova.view.user.QuestionPanel'); tabPanel.insert(1, tabPanel.userQuestionsPanel); } else { tabPanel.userQuestionsPanel.tab.show(); } /* add feedback statistic panel*/ if (!tabPanel.feedbackTabPanel) { tabPanel.feedbackTabPanel = Ext.create('ARSnova.view.feedback.TabPanel'); tabPanel.insert(2, tabPanel.feedbackTabPanel); } else { tabPanel.feedbackTabPanel.tab.show(); tabPanel.feedbackTabPanel.renew(); } target = features.liveClicker ? tabPanel.feedbackTabPanel : tabPanel.userTabPanel; tabPanel.animateActiveItem(target, animation); } /* add feedback questions panel*/ if (!tabPanel.feedbackQuestionsPanel) { tabPanel.feedbackQuestionsPanel = Ext.create('ARSnova.view.feedbackQuestions.TabPanel'); if (ARSnova.app.userRole === ARSnova.app.USER_ROLE_SPEAKER) { tabPanel.insert(2, tabPanel.feedbackQuestionsPanel); } else { tabPanel.insert(4, tabPanel.feedbackQuestionsPanel); } } if (ARSnova.app.userRole === ARSnova.app.USER_ROLE_SPEAKER) { tabPanel.feedbackQuestionsPanel.tab.show(); } else { tabPanel.feedbackQuestionsPanel.tab.hide(); } ARSnova.app.getController('Feature').applyFeatures(); ARSnova.app.sessionModel.sessionIsActive = true; tabPanel.feedbackQuestionsPanel.questionsPanel.prepareQuestionList(); hideLoadMask(); }, update: function (sessionInfo) { var session = ARSnova.app.sessionModel; session.setData(sessionInfo); session.validate(); session.update({ success: function (response) { var fullSession = Ext.decode(response.responseText); localStorage.setItem('sessionId', fullSession._id); localStorage.setItem('name', fullSession.name); localStorage.setItem('shortName', fullSession.shortName); localStorage.setItem('active', fullSession.active ? 1 : 0); localStorage.setItem('courseId', fullSession.courseId || ""); localStorage.setItem('courseType', fullSession.courseType || ""); localStorage.setItem('creationTime', fullSession.creationTime); localStorage.setItem('keyword', fullSession.keyword); ARSnova.app.isSessionOwner = true; }, failure: function (response) { Ext.Msg.alert("Hinweis!", "Die Verbindung zum Server konnte nicht hergestellt werden"); } }); }, loadFeatureOptions: function (options, sessionCreation) { var activePanel = ARSnova.app.mainTabPanel.tabPanel.getActiveItem(); var useCasePanel = Ext.create('ARSnova.view.diagnosis.UseCasePanel', { options: options, sessionCreationMode: sessionCreation, inClassSessionEntry: !sessionCreation }); activePanel.animateActiveItem(useCasePanel, 'slide'); }, validateSessionOptions: function (options) { var session = ARSnova.app.sessionModel; session.setData({ type: 'session', name: options.name.trim(), shortName: options.shortName.trim(), creator: localStorage.getItem('login'), courseId: options.courseId, courseType: options.courseType, creationTime: Date.now(), ppAuthorName: options.ppAuthorName, ppAuthorMail: options.ppAuthorMail, ppUniversity: options.ppUniversity, ppLogo: options.ppLogo, ppSubject: options.ppSubject, ppLicense: options.ppLicense, ppDescription: options.ppDescription, ppFaculty: options.ppFaculty, ppLevel: options.ppLevel, sessionType: options.sessionType }); session.set('_id', undefined); var validation = session.validate(); if (!validation.isValid()) { Ext.Msg.alert('Hinweis', 'Bitte alle markierten Felder ausfüllen.'); var panel = ARSnova.app.mainTabPanel.tabPanel.homeTabPanel.newSessionPanel; panel.down('fieldset').items.items.forEach(function (el) { if (el.xtype === 'textfield') { el.removeCls("required"); } }); validation.items.forEach(function (el) { panel.down('textfield[name=' + el.getField() + ']').addCls("required"); }); /* activate inputElements in newSessionPanel */ if (options.lastPanel && typeof options.lastPanel.enableInputElements() === 'function') { options.lastPanel.enableInputElements(); } return false; } return session; }, create: function (options) { var session = this.validateSessionOptions(options); var hideLoadMask = ARSnova.app.showLoadIndicator(Messages.LOAD_MASK_SAVE, 10000); if (!session) { return; } session.create({ success: function (response) { var fullSession = Ext.decode(response.responseText); var loginName = ""; var loginMode = localStorage.getItem("loginMode"); sessionStorage.setItem('keyword', fullSession.keyword); localStorage.setItem('sessionId', fullSession._id); ARSnova.app.getController('Auth').services.then(function (services) { services.forEach(function (service) { if (loginMode === service.id) { loginName = "guest" === service.id ? Messages.GUEST : service.name; } }); var messageBox = Ext.create('Ext.MessageBox', { title: Messages.SESSION + ' ID: ' + fullSession.keyword, message: Messages.ON_SESSION_CREATION_1.replace(/###/, fullSession.keyword), cls: 'newSessionMessageBox', listeners: { show: hideLoadMask, hide: function () { ARSnova.app.getController('Sessions').login({keyword: fullSession.keyword}); var panel = ARSnova.app.mainTabPanel.tabPanel.homeTabPanel; panel.setActiveItem(panel.mySessionsPanel); /* activate inputElements in newSessionPanel */ if (options.lastPanel && typeof options.lastPanel.enableInputElements() === 'function') { options.lastPanel.enableInputElements(); } this.destroy(); } } }); messageBox.setButtons([{ text: Messages.CONTINUE, itemId: 'continue', ui: 'action', handler: function () { if (!this.readyToClose) { messageBox.setMessage(''); messageBox.setTitle(Messages.SESSION + ' ID: ' + fullSession.keyword); messageBox.setHtml("<div class='x-msgbox-text x-layout-box-item' +" + " style='margin-top: -10px;'>" + Messages.ON_SESSION_CREATION_2.replace(/###/, loginName + "-Login " + "<div style='display: inline-block;'" + "class='text-icons login-icon-" + loginMode + "'></div> " + (loginMode === "guest" ? Messages.ON_THIS_DEVICE : "")) + ".</div>"); this.readyToClose = true; } else { messageBox.hide(); if (messageBox.showFeatureError) { Ext.Msg.alert("", Messages.FEATURE_SETTINGS_COULD_NOT_BE_SAVED); } } } }]); if (options.features) { ARSnova.app.sessionModel.changeFeatures(sessionStorage.getItem("keyword"), options.features, { success: function () { messageBox.show(); }, failure: function () { messageBox.showFeatureError = true; messageBox.show(); } }); } else { messageBox.show(); } }); }, failure: function (records, operation) { Ext.Msg.alert("Hinweis!", "Die Verbindung zum Server konnte nicht hergestellt werden"); if (options.lastPanel && typeof options.lastPanel.enableInputElements() === 'function') { options.lastPanel.enableInputElements(); } } }); }, changeRole: function () { var tabPanel = ARSnova.app.mainTabPanel.tabPanel; var hideLoadMask = ARSnova.app.showLoadIndicator(Messages.CHANGE_ROLE + '...', 2000); var reloadSession = function (animationDirection, onAnimationEnd) { tabPanel.updateHomeBadge(); ARSnova.app.socket.setSession(null); ARSnova.app.socket.setSession(sessionStorage.getItem('keyword')); ARSnova.app.getController('Feature').lastUpdate = Date.now(); onAnimationEnd = (typeof onAnimationEnd === 'function') ? onAnimationEnd : hideLoadMask; tabPanel.feedbackQuestionsPanel.initializeQuestionsPanel(); ARSnova.app.getController('Sessions').reloadData({ listeners: {animationend: onAnimationEnd}, direction: animationDirection, type: 'flip' }); }; if (ARSnova.app.userRole === ARSnova.app.USER_ROLE_SPEAKER) { localStorage.setItem('lastVisitedRole', ARSnova.app.USER_ROLE_SPEAKER); localStorage.setItem('role', ARSnova.app.USER_ROLE_STUDENT); ARSnova.app.userRole = ARSnova.app.USER_ROLE_STUDENT; /* hide speaker tab panel and destroy listeners */ tabPanel.speakerTabPanel.tab.hide(); tabPanel.speakerTabPanel.inClassPanel.destroyListeners(); reloadSession('right'); } else { if (localStorage.getItem('lastVisitedRole') === ARSnova.app.USER_ROLE_SPEAKER) { localStorage.setItem('role', ARSnova.app.USER_ROLE_SPEAKER); ARSnova.app.userRole = ARSnova.app.USER_ROLE_SPEAKER; localStorage.removeItem('lastVisitedRole'); /* hide user tab panels and destroy listeners */ tabPanel.userTabPanel.tab.hide(); tabPanel.userQuestionsPanel.tab.hide(); tabPanel.userTabPanel.inClassPanel.destroyListeners(); reloadSession('left', function () { /* remove user tab panel and user questions panel*/ tabPanel.remove(tabPanel.userQuestionsPanel); tabPanel.remove(tabPanel.userTabPanel); delete tabPanel.userQuestionsPanel; delete tabPanel.userTabPanel; hideLoadMask(); }); } } }, checkExistingSessionLogin: function () { if (localStorage.getItem('lastVisitedRole') === ARSnova.app.USER_ROLE_SPEAKER) { localStorage.setItem('role', ARSnova.app.USER_ROLE_SPEAKER); ARSnova.app.userRole = ARSnova.app.USER_ROLE_SPEAKER; localStorage.removeItem('lastVisitedRole'); } if (sessionStorage.getItem("keyword")) { return true; } return false; }, setActive: function (options) { ARSnova.app.sessionModel.lock(sessionStorage.getItem("keyword"), options.active, { success: function () { var sessionStatus = ARSnova.app.mainTabPanel.tabPanel.speakerTabPanel.inClassPanel.inClassActions.sessionStatusButton; if (options.active) { sessionStatus.sessionOpenedSuccessfully(); } else { sessionStatus.sessionClosedSuccessfully(); } }, failure: function (records, operation) { Ext.Msg.alert("Hinweis!", "Session speichern war nicht erfolgreich"); } }); }, setLearningProgressOptions: function (options) { ARSnova.app.sessionModel.setLearningProgressOptions(options); }, getLearningProgressOptions: function () { return ARSnova.app.sessionModel.getLearningProgress(); }, getCourseLearningProgress: function (options) { ARSnova.app.sessionModel.getCourseLearningProgressWithOptions( sessionStorage.getItem("keyword"), options.progress, options.callbacks ); }, getMyLearningProgress: function (options) { ARSnova.app.sessionModel.getMyLearningProgressWithOptions( sessionStorage.getItem("keyword"), options.progress, options.callbacks ); } });
dhx/arsnova-mobile
src/main/webapp/app/controller/Sessions.js
JavaScript
gpl-3.0
21,215
#!/usr/bin/env php <?php /* * Copyright (C) 2014 Jonas Felix <jf@cabag.ch> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * use composer autoloader if possible * it has to work without composer */ if(include('vendor/autoload.php')) { define('FLYREPO_COMPOSER', true); } else { define('FLYREPO_COMPOSER', false); require_once('nocomposerAutoloader.php'); } try { $clInterface = \cabservicesag\FlyRepo\ClInterface::start($argv)->run(); } catch (Exception $flyRepoException ) { print($flyRepoException->getMessage()."\n"); exit(1); }
cabservicesag/flyrepo
flyrepo.php
PHP
gpl-3.0
1,153
package pattern.creazione.abstractfactory.ex1; public abstract class AstrattaA { public abstract void info(); }
Ficcadenti/java-example
Pattern/pattern/src/pattern/creazione/abstractfactory/ex1/AstrattaA.java
Java
gpl-3.0
114
/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the demonstration applications of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** BSD License Usage ** Alternatively, you may use this file under the terms of the BSD license ** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of The Qt Company Ltd nor the names of its ** contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "pathstroke.h" #include <QApplication> int main(int argc, char **argv) { Q_INIT_RESOURCE(pathstroke); QApplication app(argc, argv); bool smallScreen = QApplication::arguments().contains("-small-screen"); PathStrokeWidget pathStrokeWidget(smallScreen); QStyle *arthurStyle = new ArthurStyle(); pathStrokeWidget.setStyle(arthurStyle); QList<QWidget *> widgets = pathStrokeWidget.findChildren<QWidget *>(); foreach (QWidget *w, widgets) { w->setStyle(arthurStyle); w->setAttribute(Qt::WA_AcceptTouchEvents); } if (smallScreen) pathStrokeWidget.showFullScreen(); else pathStrokeWidget.show(); #ifdef QT_KEYPAD_NAVIGATION QApplication::setNavigationMode(Qt::NavigationModeCursorAuto); #endif return app.exec(); }
geminy/aidear
oss/qt/qt-everywhere-opensource-src-5.9.0/qtbase/examples/widgets/painting/pathstroke/main.cpp
C++
gpl-3.0
3,281
<?php if (!isConnect('admin')) { throw new Exception('{{401 - Accès non autorisé}}'); } $page = init('page', 1); $logfile = init('logfile'); $list_logfile = array(); $dir = opendir('log/'); $logExist = false; while ($file = readdir($dir)) { if ($file != '.' && $file != '..' && $file != '.htaccess' && !is_dir('log/' . $file)) { $list_logfile[] = $file; if ($logfile == $file) { $logExist = true; } } } natcasesort($list_logfile); ?> <div class="row row-overflow"> <div class="col-lg-2 col-md-3 col-sm-4" id="div_displayLogList"> <div class="bs-sidebar"> <ul id="ul_object" class="nav nav-list bs-sidenav"> <li class="filter" style="margin-bottom: 5px;"><input class="filter form-control input-sm" placeholder="{{Rechercher}}" style="width: 100%"/></li> <?php foreach ($list_logfile as $file) { if ($file == $logfile) { echo '<li class="cursor li_log active" data-log="' . $file . '" ><a>' . $file . '</a></li>'; } else { echo '<li class="cursor li_log" data-log="' . $file . '"><a>' . $file . '</a></li>'; } } ?> </ul> </div> </div> <div class="col-lg-10 col-md-9 col-sm-8"> <a class="btn btn-danger pull-right" id="bt_removeAllLog"><i class="fa fa-trash-o"></i> {{Supprimer tous}}</a> <a class="btn btn-danger pull-right" id="bt_removeLog"><i class="fa fa-trash-o"></i> {{Supprimer}}</a> <a class="btn btn-warning pull-right" id="bt_clearLog"><i class="fa fa-times"></i> {{Vider}}</a> <a class="btn btn-success pull-right" id="bt_downloadLog"><i class="fa fa-cloud-download"></i> {{Télécharger}}</a> <a class="btn btn-warning pull-right" data-state="1" id="bt_globalLogStopStart"><i class="fa fa-pause"></i> {{Pause}}</a> <input style="max-width: 150px;" class="form-control pull-right" id="in_globalLogSearch" placeholder="{{Rechercher}}" /> <br/><br/><br/> <pre id='pre_globallog' style='overflow: auto; height: calc(100% - 70px);with:100%;'></pre> </div> </div> <?php include_file('desktop', 'log', 'js');?>
totovaauski/core
desktop/php/log.php
PHP
gpl-3.0
1,982
using FractalViewer.Common; namespace FractalViewer.FractalSpace { class Julia_SanMarco : Mandelbrot { public Julia_SanMarco(int newWidth, int newHeight, FormControlObserver sbo, bool statusbar) : base(newWidth, newHeight, sbo, statusbar) { //default san marco window is assigned here start = new ComplexWindow(new Complex(-1.6d, 1.2d), new Complex(1.6d, -1.2d)); cWindow = new ComplexWindow(new Complex(-1.6d, 1.2d), new Complex(1.6d, -1.2d)); } //see Mandelbrot.cs for iterate comment protected override int iterate(int x, int y) { int iterations = 0; Complex origin = new Complex(-.75, 0); Complex spot = complexConvert(x, y); double currentDist = 0; while ((currentDist <= escapeDist) && (++iterations <= detailLevel)) { spot = spot.power(2).add(origin); currentDist = findDist(origin, spot); } if (iterations >= detailLevel) { return ((int)(100 / currentDist)); //return 0; } return iterations; } } }
espaulding/FractalViewer
FractalViewer/FractalSpace/Julia_SanMarco.cs
C#
gpl-3.0
1,226
/* This file is part of TSRE5. * * TSRE5 - train sim game engine and MSTS/OR Editors. * Copyright (C) 2016 Piotr Gadecki <pgadecki@gmail.com> * * Licensed under GNU General Public License 3.0 or later. * * See LICENSE.md or https://www.gnu.org/licenses/gpl.html */ #include "ProceduralShape.h" #include "ObjFile.h" #include "Game.h" #include "GLMatrix.h" #include "TrackShape.h" #include "Route.h" #include "TSectionDAT.h" #include <QDateTime> #include <QFile> #include <math.h> #include "Intersections.h" #include "ComplexLine.h" #include "ShapeTemplates.h" QHash<QString, QVector<OglObj*>> ProceduralShape::Shapes; ShapeTemplates *ProceduralShape::ShapeTemplateFile = NULL; GlobalDefinitions *ProceduralShape::GlobalDefinitionFile = NULL; bool ProceduralShape::Loaded = false; QMap<QString, ObjFile*> ProceduralShape::Files; float ProceduralShape::Alpha = 0; unsigned int ProceduralShape::ShapeCount = 0; ObjFile* ProceduralShape::GetObjFile(QString name) { QString pathRoute = Game::root + "/routes/" + Game::route + "/procedural/" + name; pathRoute.replace("//", "/"); QString pathApp = QString("tsre_appdata/") + Game::AppDataVersion + "/procedural/" + name; pathApp.replace("//", "/"); QString path = pathApp; QFile file(pathRoute); if(file.exists()) path = pathRoute; if (Files[path] == NULL) Files[path] = new ObjFile(path); return Files[path]; } QString ProceduralShape::GetTexturePath(QString textureName){ QString pathRoute = Game::root + "/routes/" + Game::route + "/procedural/" + textureName; pathRoute.replace("//", "/"); QString pathApp = QString("tsre_appdata/") + Game::AppDataVersion + "/procedural/" + textureName; pathApp.replace("//", "/"); QString path = pathApp; QFile file(pathRoute); if(file.exists()) path = pathRoute; return path; } void ProceduralShape::Load() { if(Loaded) return; // Load Templates ShapeTemplateFile = new ShapeTemplates(); Alpha = -0.3; Loaded = true; } QString ProceduralShape::GetShapeHash(QString templateName, TrackShape* tsh, QMap<int, float> &angles, int shapeOffset){ QString angless; QMapIterator<int, float> i(angles); while (i.hasNext()) { i.next(); angless += QString::number(i.key(), 16) + QString::number((int)(i.value()*100), 16) + "_"; } return tsh->getHashString() + QString::number(shapeOffset, 16) + angless + templateName; //return QString::number(QTime::currentTime().msecsSinceStartOfDay()); } QString ProceduralShape::GetShapeHash(QString templateName, QVector<TSection> &sections, int shapeOffset){ QString sectionHash; for(int i = 0; i < sections.size(); i++) sectionHash += QString::number(sections[i].getHash(), 16); return sectionHash + QString::number(shapeOffset, 16) + templateName; //return QString::number(QTime::currentTime().msecsSinceStartOfDay()); } QString ProceduralShape::GetShapeHash(QString templateName, ComplexLine &line, int shapeOffset){ QString lineHash = line.getHash(); return lineHash + QString::number(shapeOffset, 16) + templateName; //return QString::number(QTime::currentTime().msecsSinceStartOfDay()); } void ProceduralShape::GetShape(QString templateName, QVector<OglObj*>& shape, TrackShape* tsh, QMap<int, float> &angles) { QString hash = ProceduralShape::GetShapeHash(templateName, tsh, angles, 0); if(ProceduralShape::Shapes[hash].size() == 0){ qDebug() << "New Procedural Shape: "<< ShapeCount++ << hash; ProceduralShape::GenShape(templateName, ProceduralShape::Shapes[hash], tsh, angles); } shape.append(ProceduralShape::Shapes[hash]); } void ProceduralShape::GenShape(QString templateName, QVector<OglObj*>& shape, TrackShape* tsh, QMap<int, float> &angles) { if (!Loaded) Load(); if (tsh == NULL) return; /*if(tsh->numpaths == 2 && tsh->xoverpts > 0){ return GenTrackShape(shape, tsh, angles); } if(tsh->numpaths == 2 && tsh->mainroute > -1){ return GenTrackShape(shape, tsh, angles); }*/ if(templateName == "" || templateName == "DEFAULT") templateName = "DefaultTrack"; if(ShapeTemplateFile->templates[templateName] == NULL) return; ShapeTemplate *sTemplate = ShapeTemplateFile->templates[templateName]; ComplexLine *line = new ComplexLine[tsh->numpaths]; for (int j = 0; j < tsh->numpaths; j++) { TrackShape::SectionIdx *section = &tsh->path[j]; QVector<TSection> sections; for (int i = 0; i < section->n; i++) { if (Game::currentRoute->tsection->sekcja[(int) section->sect[i]] != NULL) sections.push_back(*Game::currentRoute->tsection->sekcja[(int) section->sect[i]]); } line[j].init(sections); } QHashIterator<QString, ShapeTemplateElement*> i(sTemplate->elements); while (i.hasNext()) { i.next(); if(i.value() == NULL) continue; if(i.value()->type == ShapeTemplateElement::TIE){ if(tsh->numpaths == 2 && tsh->xoverpts > 0){ GenAdvancedTie(i.value(), shape, tsh, angles); } else if(tsh->numpaths == 2 && tsh->mainroute > -1){ GenAdvancedTie(i.value(), shape, tsh, angles); } else { for (int j = 0; j < tsh->numpaths; j++) { GenTie(i.value(), shape, line[j], tsh->path[j].pos, -tsh->path[j].rotDeg, angles[j * 2], angles[j * 2 + 1]); } } } if(i.value()->type == ShapeTemplateElement::RAIL) for (int j = 0; j < tsh->numpaths; j++) GenRails(i.value(), shape, line[j], tsh->path[j].pos, -tsh->path[j].rotDeg, angles[j * 2], angles[j * 2 + 1]); if(i.value()->type == ShapeTemplateElement::BALLAST) for (int j = 0; j < tsh->numpaths; j++) GenBallast(i.value(), shape, line[j], tsh->path[j].pos, -tsh->path[j].rotDeg, angles[j * 2], angles[j * 2 + 1]); } delete[] line; return; } void ProceduralShape::GetShape(QString templateName, QVector<OglObj*>& shape, QVector<TSection> &sections, int shapeOffset) { QString hash = ProceduralShape::GetShapeHash(templateName, sections, shapeOffset); if(ProceduralShape::Shapes[hash].size() == 0){ qDebug() << "New Procedural Shape: "<< ShapeCount++ << hash; ProceduralShape::GenShape(templateName, ProceduralShape::Shapes[hash], sections, shapeOffset); } shape.append(ProceduralShape::Shapes[hash]); } void ProceduralShape::GenShape(QString templateName, QVector<OglObj*>& shape, QVector<TSection> &sections, int shapeOffset) { if (!Loaded) Load(); ComplexLine line; line.init(sections); ProceduralShape::GenShape(templateName, shape, line, shapeOffset); } void ProceduralShape::GetShape(QString templateName, QVector<OglObj*>& shape, ComplexLine& line, int shapeOffset) { QString hash = ProceduralShape::GetShapeHash(templateName, line, shapeOffset); if(ProceduralShape::Shapes[hash].size() == 0){ qDebug() << "New Procedural Shape: "<< ShapeCount++ << hash; ProceduralShape::GenShape(templateName, ProceduralShape::Shapes[hash], line, shapeOffset); } shape.append(ProceduralShape::Shapes[hash]); } void ProceduralShape::GenShape(QString templateName, QVector<OglObj*>& shape, ComplexLine& line, int shapeOffset){ //unsigned long long int timeNow = QDateTime::currentMSecsSinceEpoch(); Alpha = -0.3; if(templateName == "" || templateName == "DEFAULT") templateName = "DefaultTrack"; if(ShapeTemplateFile->templates[templateName] == NULL) return; ShapeTemplate *sTemplate = ShapeTemplateFile->templates[templateName]; QHashIterator<QString, ShapeTemplateElement*> i(sTemplate->elements); while (i.hasNext()) { i.next(); if(i.value()->type == NULL) continue; if(i.value()->type == ShapeTemplateElement::TIE) GenTie(i.value(), shape, line); if(i.value()->type == ShapeTemplateElement::RAIL) GenRails(i.value(), shape, line); if(i.value()->type == ShapeTemplateElement::BALLAST) GenBallast(i.value(), shape, line); if(i.value()->type == ShapeTemplateElement::STRETCH) GenStretch(i.value(), shape, line, shapeOffset); if(i.value()->type == ShapeTemplateElement::POINT) GenPointShape(i.value(), shape, line, shapeOffset); } } void ProceduralShape::GenRails(ShapeTemplateElement *stemplate, QVector<OglObj*> &shape, ComplexLine &line) { float* p = new float[2000000]; float* ptr = p; float q[4]; float posRot[6]; float matrix1[16]; float matrix2[16]; float vOffset[3]; ObjFile *tFile; QString* texturePath; tFile = GetObjFile(stemplate->shape.first()); float step = 3; for (float i = 0; i < line.length; i += step) { line.getDrawPosition(posRot, i, stemplate->xOffset); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); Vec3::set(vOffset, stemplate->xOffset, 0.0, 0.0); Vec3::transformQuat(vOffset, vOffset, q); Vec3::add(posRot, vOffset, posRot); Mat4::fromRotationTranslation(matrix1, q, posRot); line.getDrawPosition(posRot, i + step, stemplate->xOffset); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); Vec3::set(vOffset, stemplate->xOffset, 0.0, 0.0); Vec3::transformQuat(vOffset, vOffset, q); Vec3::add(posRot, vOffset, posRot); Mat4::fromRotationTranslation(matrix2, q, posRot); PushShapePartExpand(ptr, tFile, stemplate->yOffset, matrix1, matrix2, q, i, i + step); } texturePath = new QString(ProceduralShape::GetTexturePath(stemplate->texture)); shape.push_back(new OglObj()); shape.back()->setMaterial(texturePath); shape.back()->init(p, ptr - p, RenderItem::VNTA, GL_TRIANGLES); shape.back()->setDistanceRange(stemplate->minDistance, stemplate->maxDistance); delete[] p; } void ProceduralShape::GenRails(ShapeTemplateElement *stemplate, QVector<OglObj*>& shape, ComplexLine& line, float* sPos, float sAngle, float angleB, float angleE) { float matrixS[16]; float* p = new float[4000000]; float* ptr = p; float q[4]; float qr[4]; float posRot[6]; float matrix1[16]; float matrix2[16]; ObjFile *tFile; QString* texturePath; float pp[3]; float zangle; float vOffset[3]; Quat::fill(q); Quat::rotateY(q, q, sAngle * M_PI / 180.0); Vec3::set(pp, -sPos[0], sPos[1], sPos[2]); Mat4::fromRotationTranslation(matrixS, q, pp); tFile = GetObjFile(stemplate->shape.first()); float step = 3; for (float i = 0; i < line.length; i += step) { line.getDrawPosition(posRot, i, stemplate->xOffset); Quat::fill(qr); Quat::rotateY(qr, qr, sAngle * M_PI / 180.0); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); zangle = angleB*(1.0 - i / line.length) + angleE*(i / line.length); Quat::rotateZ(q, q, zangle); Vec3::set(vOffset, stemplate->xOffset, 0.0, 0.0); Vec3::transformQuat(vOffset, vOffset, q); Vec3::add(posRot, vOffset, posRot); Mat4::fromRotationTranslation(matrix1, q, posRot); Mat4::multiply(matrix1, matrixS, matrix1); line.getDrawPosition(posRot, i + step, stemplate->xOffset); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); zangle = angleB*(1.0 - (i + step) / line.length) + angleE*((i + step) / line.length); Quat::rotateZ(q, q, zangle); Vec3::set(vOffset, stemplate->xOffset, 0.0, 0.0); Vec3::transformQuat(vOffset, vOffset, q); Vec3::add(posRot, vOffset, posRot); Mat4::fromRotationTranslation(matrix2, q, posRot); Mat4::multiply(matrix2, matrixS, matrix2); Quat::multiply(qr, qr, q); PushShapePartExpand(ptr, tFile, stemplate->yOffset, matrix1, matrix2, qr, i, i + step); } texturePath = new QString(ProceduralShape::GetTexturePath(stemplate->texture)); shape.push_back(new OglObj()); shape.back()->setMaterial(texturePath); shape.back()->init(p, ptr - p, RenderItem::VNTA, GL_TRIANGLES); shape.back()->setDistanceRange(stemplate->minDistance, stemplate->maxDistance); delete[] p; } void ProceduralShape::GenPointShape(ShapeTemplateElement *stemplate, QVector<OglObj*> &shape, ComplexLine &line, int shapeOffset) { float* p = new float[2000000]; float* ptr = p; float q[4]; float posRot[6]; float matrix1[16]; float matrix2[16]; ObjFile *tFile; QString* texturePath; shapeOffset = shapeOffset % stemplate->shape.size(); tFile = GetObjFile(stemplate->shape[shapeOffset]); line.getDrawPosition(posRot, 0); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); Mat4::fromRotationTranslation(matrix1, q, posRot); //PushShapePart(ptr, tFile, 0.0, matrix1, q, line.length); PushShapePart(ptr, tFile, 0.0, matrix1, q); texturePath = new QString(ProceduralShape::GetTexturePath(stemplate->texture)); shape.push_back(new OglObj()); shape.back()->setMaterial(texturePath); shape.back()->init(p, ptr - p, RenderItem::VNTA, GL_TRIANGLES); shape.back()->setDistanceRange(stemplate->minDistance, stemplate->maxDistance); ptr = p; delete[] p; } void ProceduralShape::GenStretch(ShapeTemplateElement *stemplate, QVector<OglObj*> &shape, ComplexLine &line, int shapeOffset) { float* p = new float[2000000]; float* ptr = p; float q[4]; float posRot[6]; float matrix1[16]; float matrix2[16]; ObjFile *tFile; QString* texturePath; shapeOffset = shapeOffset % stemplate->shape.size(); tFile = GetObjFile(stemplate->shape[shapeOffset]); line.getDrawPosition(posRot, 0); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); Mat4::fromRotationTranslation(matrix1, q, posRot); PushShapePartStretch(ptr, tFile, 0.0, matrix1, q, line.length); texturePath = new QString(ProceduralShape::GetTexturePath(stemplate->texture)); shape.push_back(new OglObj()); shape.back()->setMaterial(texturePath); shape.back()->init(p, ptr - p, RenderItem::VNTA, GL_TRIANGLES); shape.back()->setDistanceRange(stemplate->minDistance, stemplate->maxDistance); ptr = p; delete[] p; } void ProceduralShape::GenBallast(ShapeTemplateElement *stemplate, QVector<OglObj*> &shape, ComplexLine &line) { float* p = new float[2000000]; float* ptr = p; float q[4]; float posRot[6]; float matrix1[16]; float matrix2[16]; ObjFile *tFile; QString* texturePath; tFile = GetObjFile(stemplate->shape.first()); float step = 4; for (float i = 0; i < line.length; i += step) { line.getDrawPosition(posRot, i); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); Mat4::fromRotationTranslation(matrix1, q, posRot); line.getDrawPosition(posRot, i + step); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); Mat4::fromRotationTranslation(matrix2, q, posRot); PushShapePartExpand(ptr, tFile, stemplate->yOffset, matrix1, matrix2, q, i, i + step); } texturePath = new QString(ProceduralShape::GetTexturePath(stemplate->texture)); shape.push_back(new OglObj()); shape.back()->setMaterial(texturePath); shape.back()->init(p, ptr - p, RenderItem::VNTA, GL_TRIANGLES); shape.back()->setDistanceRange(stemplate->minDistance, stemplate->maxDistance); ptr = p; delete[] p; } void ProceduralShape::GenBallast(ShapeTemplateElement *stemplate, QVector<OglObj*>& shape, ComplexLine& line, float* sPos, float sAngle, float angleB, float angleE) { float matrixS[16]; float* p = new float[4000000]; float* ptr = p; float q[4]; float qr[4]; float posRot[6]; float matrix1[16]; float matrix2[16]; ObjFile *tFile; QString* texturePath; float pp[3]; float zangle; Quat::fill(q); Quat::rotateY(q, q, sAngle * M_PI / 180.0); Vec3::set(pp, -sPos[0], sPos[1], sPos[2]); Mat4::fromRotationTranslation(matrixS, q, pp); tFile = GetObjFile(stemplate->shape.first()); float step = 4; for (float i = 0; i < line.length; i += step) { line.getDrawPosition(posRot, i); Quat::fill(qr); Quat::rotateY(qr, qr, sAngle * M_PI / 180.0); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); zangle = angleB*(1.0 - i / line.length) + angleE*(i / line.length); Quat::rotateZ(q, q, zangle); Mat4::fromRotationTranslation(matrix1, q, posRot); Mat4::multiply(matrix1, matrixS, matrix1); line.getDrawPosition(posRot, i + step); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); zangle = angleB*(1.0 - (i + step) / line.length) + angleE*((i + step) / line.length); Quat::rotateZ(q, q, zangle); Mat4::fromRotationTranslation(matrix2, q, posRot); Mat4::multiply(matrix2, matrixS, matrix2); Quat::multiply(qr, qr, q); PushShapePartExpand(ptr, tFile, stemplate->yOffset, matrix1, matrix2, qr, i, i + step); } texturePath = new QString(ProceduralShape::GetTexturePath(stemplate->texture)); shape.push_back(new OglObj()); shape.back()->setMaterial(texturePath); shape.back()->init(p, ptr - p, RenderItem::VNTA, GL_TRIANGLES); shape.back()->setDistanceRange(stemplate->minDistance, stemplate->maxDistance); delete[] p; } void ProceduralShape::GenTie(ShapeTemplateElement *stemplate, QVector<OglObj*> &shape, ComplexLine &line) { float* p = new float[2000000]; float* ptr = p; float q[4]; float posRot[6]; float matrix1[16]; float matrix2[16]; ObjFile *tFile; QString* texturePath; tFile = GetObjFile(stemplate->shape.first()); for (float i = 0; i < line.length; i += 0.65) { line.getDrawPosition(posRot, i); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); Mat4::fromRotationTranslation(matrix1, q, posRot); PushShapePart(ptr, tFile, 0.155, matrix1, q); } texturePath = new QString(ProceduralShape::GetTexturePath(stemplate->texture)); shape.push_back(new OglObj()); shape.back()->setMaterial(texturePath); shape.back()->init(p, ptr - p, RenderItem::VNTA, GL_TRIANGLES); shape.back()->setDistanceRange(stemplate->minDistance, stemplate->maxDistance); delete[] p; } void ProceduralShape::GenTie(ShapeTemplateElement *stemplate, QVector<OglObj*> &shape, ComplexLine &line, float *sPos, float sAngle, float angleB, float angleE) { float matrixS[16]; float* p = new float[4000000]; float* ptr = p; float q[4]; float qr[4]; float posRot[6]; float matrix1[16]; float matrix2[16]; ObjFile *tFile; QString* texturePath; float pp[3]; float zangle; Quat::fill(q); Quat::rotateY(q, q, sAngle * M_PI / 180.0); Vec3::set(pp, -sPos[0], sPos[1], sPos[2]); Mat4::fromRotationTranslation(matrixS, q, pp); tFile = GetObjFile(stemplate->shape.first()); for (float i = 0; i < line.length; i += 0.65) { line.getDrawPosition(posRot, i); Quat::fill(qr); Quat::rotateY(qr, qr, sAngle * M_PI / 180.0); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); zangle = angleB * (1.0 - i / line.length) + angleE * (i / line.length); Quat::rotateZ(q, q, zangle); Mat4::fromRotationTranslation(matrix1, q, posRot); Quat::multiply(qr, qr, q); Mat4::multiply(matrix1, matrixS, matrix1); PushShapePart(ptr, tFile, 0.155, matrix1, qr); } texturePath = new QString(ProceduralShape::GetTexturePath(stemplate->texture)); shape.push_back(new OglObj()); shape.back()->setMaterial(texturePath); shape.back()->init(p, ptr - p, RenderItem::VNTA, GL_TRIANGLES); shape.back()->setDistanceRange(stemplate->minDistance, stemplate->maxDistance); delete[] p; } void ProceduralShape::GenAdvancedTie(ShapeTemplateElement *stemplate, QVector<OglObj*>& shape, TrackShape* tsh, QMap<int, float>& angles) { float matrixS[16]; float matrixS1[16]; float matrixS2[16]; QVector<QVector < ShapePrimitive>> primitives; if (tsh->numpaths == 2) { //for(int j = 0; j < tsh->numpaths; j++){ TrackShape::SectionIdx *section = &tsh->path[0]; QVector<TSection> sections1; QVector<TSection> sections2; for (int i = 0; i < section->n; i++) { if (Game::currentRoute->tsection->sekcja[(int) section->sect[i]] != NULL) sections1.push_back(*Game::currentRoute->tsection->sekcja[(int) section->sect[i]]); } section = &tsh->path[1]; for (int i = 0; i < section->n; i++) { if (Game::currentRoute->tsection->sekcja[(int) section->sect[i]] != NULL) sections2.push_back(*Game::currentRoute->tsection->sekcja[(int) section->sect[i]]); } //float* p = new float[4000000]; //float* ptr = p; float q[4]; float q1[4]; float q2[4]; float qr[4]; float posRot[6]; float posRot1[6]; float posRot2[6]; float matrix1[16]; float matrix2[16]; ObjFile *tFile; ComplexLine line1; ComplexLine line2; line1.init(sections1); line2.init(sections2); //qDebug() << line.length << "length"; float pp[3]; float zangle; Quat::fill(q1); Quat::rotateY(q1, q1, -tsh->path[0].rotDeg * M_PI / 180.0); Vec3::set(pp, -tsh->path[0].pos[0], tsh->path[0].pos[1], tsh->path[0].pos[2]); Mat4::fromRotationTranslation(matrixS1, q1, pp); Quat::fill(q2); Quat::rotateY(q2, q2, -tsh->path[1].rotDeg * M_PI / 180.0); Vec3::set(pp, -tsh->path[1].pos[0], tsh->path[1].pos[1], tsh->path[1].pos[2]); Mat4::fromRotationTranslation(matrixS2, q2, pp); //Quat::multiply(q, q1, q2); //Quat bool junct = false; if (tsh->mainroute > -1) junct = true; primitives.push_back(QVector<ShapePrimitive>()); tFile = GetObjFile(stemplate->shape.first()); float length = line1.length; ComplexLine *line3 = &line2; int pathidx = 1; Mat4::copy(matrixS, matrixS2); if (line2.length < line1.length) { length = line2.length; line3 = &line1; pathidx = 0; Mat4::copy(matrixS, matrixS1); } float i = 0; for (i = 0; i < length; i += 0.65) { line1.getDrawPosition(posRot1, i); line2.getDrawPosition(posRot2, i); Vec3::transformMat4(posRot1, posRot1, matrixS1); Vec3::transformMat4(posRot2, posRot2, matrixS2); float distance = Vec3::dist(posRot1, posRot2)*0.5; Vec3::add(posRot, posRot1, posRot2); Vec3::scale(posRot, posRot, 0.5); posRot[3] = posRot1[3]*0.5 + posRot2[3]*0.5; posRot[4] = posRot1[4]*0.5 + posRot2[4]*0.5; posRot[5] = posRot1[5]*0.5 + posRot2[5]*0.5; Quat::fill(qr); Quat::rotateY(qr, qr, -tsh->path[0].rotDeg * M_PI / 180.0); Quat::fromRotationXYZ(q1, (float*) (posRot1 + 3)); Quat::multiply(q1, qr, q1); Quat::fill(qr); Quat::rotateY(qr, qr, -tsh->path[1].rotDeg * M_PI / 180.0); Quat::fromRotationXYZ(q2, (float*) (posRot2 + 3)); Quat::multiply(q2, qr, q2); if (!junct) Quat::slerp(q, q1, q2, 0.5); else if (tsh->mainroute == 0) Quat::copy(q, q1); else Quat::copy(q, q2); //Quat::multiply(q, q1, q2); zangle = 0; //angles[j*2]*(1.0-i/line1.length) + angles[j*2+1]*(i/line1.length); //Quat::rotateZ(q, q, zangle); Mat4::fromRotationTranslation(matrix1, q, posRot); //Quat::multiply(qr, qr, q); //Mat4::multiply(matrix1, matrixS, matrix1); primitives[0].push_back(ShapePrimitive()); primitives[0].back().data = new float[1800]; float* ptr = primitives[0].back().data; primitives[0].back().count = tFile->count; //qDebug() << "count" << tFile->count; //Vec3::copy(primitives[0].back().pos, posRot); //Vec3::transformMat4(primitives[0].back().pos, primitives[0].back().pos, matrixS); //Mat4::copy(primitives[0].back().matrix, matrix1); //Quat::copy(primitives[0].back().quat, qr); //primitives[0].back().rotY = -tsh->path[0].rotDeg*M_PI/180.0; //primitives[0].back().rotZ = zangle; //primitives[0].back().templatePtr = tFile; PushShapePart(ptr, tFile, 0.155, matrix1, q, distance); } for (; i < line3->length; i += 0.65) { line3->getDrawPosition(posRot, i); Quat::fill(qr); Quat::rotateY(qr, qr, -tsh->path[pathidx].rotDeg * M_PI / 180.0); Quat::fromRotationXYZ(q, (float*) (posRot + 3)); zangle = 0; Quat::rotateZ(q, q, zangle); Mat4::fromRotationTranslation(matrix1, q, posRot); Quat::multiply(qr, qr, q); Mat4::multiply(matrix1, matrixS, matrix1); primitives[0].push_back(ShapePrimitive()); primitives[0].back().data = new float[1800]; float* ptr = primitives[0].back().data; primitives[0].back().count = tFile->count; //qDebug() << "count" << tFile->count; Vec3::copy(primitives[0].back().pos, posRot); Vec3::transformMat4(primitives[0].back().pos, primitives[0].back().pos, matrixS); Mat4::copy(primitives[0].back().matrix, matrix1); Quat::copy(primitives[0].back().quat, qr); primitives[0].back().rotY = -tsh->path[pathidx].rotDeg * M_PI / 180.0; primitives[0].back().rotZ = zangle; primitives[0].back().templatePtr = tFile; PushShapePart(ptr, tFile, 0.155, matrix1, qr); } } /*for(int j = 0; j < tsh->numpaths; j++){ TrackShape::SectionIdx *section = &tsh->path[j]; QVector<TSection> sections; for(int i = 0; i < section->n; i++){ if(Game::currentRoute->tsection->sekcja[(int)section->sect[i]] != NULL) sections.push_back(*Game::currentRoute->tsection->sekcja[(int)section->sect[i]]); } //float* p = new float[4000000]; //float* ptr = p; float q[4]; float qr[4]; float posRot[6]; float matrix1[16]; float matrix2[16]; ObjFile *tFile; ComplexLine line; line.init(sections); //qDebug() << line.length << "length"; float pp[3]; float zangle; Quat::fill(q); Quat::rotateY(q, q, -tsh->path[j].rotDeg*M_PI/180.0); Vec3::set(pp, -tsh->path[j].pos[0], tsh->path[j].pos[1], tsh->path[j].pos[2]); Mat4::fromRotationTranslation(matrixS, q, pp); primitives.push_back(QVector<ShapePrimitive>()); tFile = GetObjFile("inbk3.obj"); for(float i = 0; i < line.length; i += 0.65){ line.getDrawPosition(posRot, i); Quat::fill(qr); Quat::rotateY(qr, qr, -tsh->path[j].rotDeg*M_PI/180.0); Quat::fromRotationXYZ(q, (float*)(posRot+3)); zangle = angles[j*2]*(1.0-i/line.length) + angles[j*2+1]*(i/line.length); Quat::rotateZ(q, q, zangle); Mat4::fromRotationTranslation(matrix1, q, posRot); Quat::multiply(qr, qr, q); Mat4::multiply(matrix1, matrixS, matrix1); primitives[j].push_back(ShapePrimitive()); primitives[j].back().data = new float[1800]; float* ptr = primitives[j].back().data; primitives[j].back().count = tFile->count; qDebug() << "count" << tFile->count; Vec3::copy(primitives[j].back().pos, posRot); Vec3::transformMat4(primitives[j].back().pos, primitives[j].back().pos, matrixS); Mat4::copy(primitives[j].back().matrix, matrix1); Quat::copy(primitives[j].back().quat, qr); primitives[j].back().rotY = -tsh->path[j].rotDeg*M_PI/180.0; primitives[j].back().rotZ = zangle; primitives[j].back().templatePtr = tFile; PushShapePart(ptr, tFile, 0.155, matrix1, qr); } } if(primitives.count() == 2){ primitives.push_back(QVector<ShapePrimitive>()); ObjFile *tFile; float pos[3]; Vec3::set(pos, 0, 0, 0); for(int j = 0; j < primitives[0].count(); j++){ for(int i = 0; i < primitives[1].count(); i++){ if(primitives[0][j].disabled || primitives[1][i].disabled) continue; if(Intersections::shapeIntersectsShape( primitives[0][j].data, primitives[1][i].data, primitives[0][j].count*9, primitives[1][i].count*9, 9, 9, pos) > 0 ){ primitives[0][j].disabled = true; primitives[1][i].disabled = true; primitives[2].push_back(ShapePrimitive()); primitives[2].back().data = new float[1800]; float* ptr = primitives[2].back().data; tFile = primitives[0][j].templatePtr; primitives[2].back().count = tFile->count; float matrix[16]; float q[4]; float pos[3]; Vec3::add(pos, primitives[0][j].pos, primitives[1][i].pos); Vec3::scale(pos, pos, 0.5); /* Quat::fill(q); float zangle = primitives[0][j].rotZ*0.5 + primitives[1][i].rotZ * 0.5; float yangle = primitives[0][j].rotY*0.5 + primitives[1][i].rotY * 0.5; Quat::rotateY(q, q, yangle); Quat::rotateZ(q, q, zangle);*/ //Quat::multiply(q, primitives[0][j].quat, primitives[1][i].quat); //Mat4::fromRotationTranslation(matrix, q, pos); //for(int i = 0; i < 16; i++){ // matrix[i] = primitives[0][j].matrix[i]*0.5 + primitives[1][i].matrix[i]*0.5; //} //Mat4::multiply(matrix, primitives[0][j].matrix, primitives[1][i].matrix); //PushShapePart(ptr, tFile, 0.155, matrix, q); //PushShapePart(ptr, tFile, 0.155, primitives[1][i].matrix, primitives[1][i].quat); //} //} //} //}*/ float* p = new float[4000000]; float* ptr = p; QString* texturePath; for (int i = 0; i < primitives.count(); i++) { for (int j = 0; j < (primitives[i]).count(); j++) { if ((primitives[i])[j].disabled) continue; memcpy(ptr, (primitives[i])[j].data, (primitives[i])[j].count * 9 * 4); ptr += (primitives[i])[j].count * 9; } } texturePath = new QString(ProceduralShape::GetTexturePath(stemplate->texture)); shape.push_back(new OglObj()); shape.back()->setMaterial(texturePath); shape.back()->init(p, ptr - p, RenderItem::VNTA, GL_TRIANGLES); shape.back()->setDistanceRange(stemplate->minDistance, stemplate->maxDistance); delete[] p; } void ProceduralShape::PushShapePart(float* &ptr, ObjFile* tFile, float offsetY, float* matrix, float* qrot, float distance) { int j = 0; float p[3]; for (int i = 0; i < tFile->count; i++) { p[0] = tFile->points[j++]; p[1] = tFile->points[j++]; p[2] = tFile->points[j++]; if (distance > 0.01) { if (p[0] > 0) p[0] += distance; if (p[0] < 0) p[0] -= distance; } Vec3::transformMat4(p, p, matrix); *ptr++ = p[0]; *ptr++ = p[1] + offsetY; *ptr++ = p[2]; p[0] = tFile->points[j++]; p[1] = tFile->points[j++]; p[2] = tFile->points[j++]; Vec3::transformQuat(p, p, qrot); *ptr++ = p[0]; *ptr++ = p[1]; *ptr++ = p[2]; *ptr++ = tFile->points[j++]; *ptr++ = tFile->points[j++]; *ptr++ = Alpha; } } void ProceduralShape::PushShapePartExpand(float* &ptr, ObjFile* tFile, float offsetY, float* matrix1, float* matrix2, float* qrot, float dist1, float dist2) { int j = 0; float p[3]; float texY = tFile->texYmin; float texYstep = tFile->texYmax - tFile->texYmin; float itexy = 0; for (int i = 0; i < tFile->count; i++) { p[0] = tFile->points[j++]; p[1] = tFile->points[j++]; p[2] = tFile->points[j++]; if (fabs(p[2]) < 0.5) { p[2] = 0; Vec3::transformMat4(p, p, matrix1); itexy = texYstep*dist1; } else { p[2] = 0; Vec3::transformMat4(p, p, matrix2); itexy = texYstep*dist2; } *ptr++ = p[0]; *ptr++ = p[1] + offsetY; *ptr++ = p[2]; p[0] = tFile->points[j++]; p[1] = tFile->points[j++]; p[2] = tFile->points[j++]; Vec3::transformQuat(p, p, qrot); *ptr++ = p[0]; *ptr++ = p[1]; *ptr++ = p[2]; *ptr++ = tFile->points[j++]; j++; *ptr++ = texY + itexy; *ptr++ = Alpha; } } void ProceduralShape::PushShapePartStretch(float* &ptr, ObjFile* tFile, float offsetY, float* matrix, float* qrot, float length) { int j = 0; float p[3]; for (int i = 0; i < tFile->count; i++) { p[0] = tFile->points[j++]; p[1] = tFile->points[j++]; p[2] = tFile->points[j++]*length; Vec3::transformMat4(p, p, matrix); *ptr++ = p[0]; *ptr++ = p[1] + offsetY; *ptr++ = p[2]; p[0] = tFile->points[j++]; p[1] = tFile->points[j++]; p[2] = tFile->points[j++]; Vec3::transformQuat(p, p, qrot); *ptr++ = p[0]; *ptr++ = p[1]; *ptr++ = p[2]; *ptr++ = tFile->points[j++]; *ptr++ = tFile->points[j++]; *ptr++ = Alpha; } }
GokuMK/TSRE5
ProceduralShape.cpp
C++
gpl-3.0
35,523
#!/usr/bin/python -tt # An incredibly simple agent. All we do is find the closest enemy tank, drive # towards it, and shoot. Note that if friendly fire is allowed, you will very # often kill your own tanks with this code. ################################################################# # NOTE TO STUDENTS # This is a starting point for you. You will need to greatly # modify this code if you want to do anything useful. But this # should help you to know how to interact with BZRC in order to # get the information you need. # # After starting the bzrflag server, this is one way to start # this code: # python agent0.py [hostname] [port] # # Often this translates to something like the following (with the # port name being printed out by the bzrflag server): # python agent0.py localhost 49857 ################################################################# import sys import math import time from bzrc import BZRC, Command class Agent(object): """Class handles all command and control logic for a teams tanks.""" def __init__(self, bzrc): self.bzrc = bzrc self.constants = self.bzrc.get_constants() self.commands = [] def tick(self, time_diff): """Some time has passed; decide what to do next.""" mytanks, othertanks, flags, shots, obstacles = self.bzrc.get_lots_o_stuff() self.mytanks = mytanks self.othertanks = othertanks self.flags = flags self.shots = shots self.enemies = [tank for tank in othertanks if tank.color != self.constants['team']] self.commands = [] for tank in mytanks: self.attack_enemies(tank) results = self.bzrc.do_commands(self.commands) def attack_enemies(self, tank): """Find the closest enemy and chase it, shooting as you go.""" best_enemy = None best_dist = 2 * float(self.constants['worldsize']) for enemy in self.enemies: if enemy.status != 'alive': continue dist = math.sqrt((enemy.x - tank.x)**2 + (enemy.y - tank.y)**2) if dist < best_dist: best_dist = dist best_enemy = enemy if best_enemy is None: command = Command(tank.index, 0, 0, False) self.commands.append(command) else: self.move_to_position(tank, best_enemy.x, best_enemy.y) def move_to_position(self, tank, target_x, target_y): """Set command to move to given coordinates.""" target_angle = math.atan2(target_y - tank.y, target_x - tank.x) relative_angle = self.normalize_angle(target_angle - tank.angle) command = Command(tank.index, 1, 2 * relative_angle, True) self.commands.append(command) def normalize_angle(self, angle): """Make any angle be between +/- pi.""" angle -= 2 * math.pi * int (angle / (2 * math.pi)) if angle <= -math.pi: angle += 2 * math.pi elif angle > math.pi: angle -= 2 * math.pi return angle def main(): # Process CLI arguments. try: execname, host, port = sys.argv except ValueError: execname = sys.argv[0] print >>sys.stderr, '%s: incorrect number of arguments' % execname print >>sys.stderr, 'usage: %s hostname port' % sys.argv[0] sys.exit(-1) # Connect. #bzrc = BZRC(host, int(port), debug=True) bzrc = BZRC(host, int(port)) agent = Agent(bzrc) prev_time = time.time() # Run the agent try: while True: time_diff = time.time() - prev_time agent.tick(time_diff) except KeyboardInterrupt: print "Exiting due to keyboard interrupt." bzrc.close() if __name__ == '__main__': main() # vim: et sw=4 sts=4
bweaver2/bzrFlag
bzagents/agent0.py
Python
gpl-3.0
3,861
/* * Copyright (C) 2013 EMBL - European Bioinformatics Institute * * All rights reserved. This file is part of the MassCascade feature for KNIME. * * The feature is free software: you can redistribute it and/or modify it under the terms of the GNU General Public * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later * version. * * The feature is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with the feature. If not, see * <http://www.gnu.org/licenses/>. * * Contributors: Stephan Beisken - initial API and implementation */ package uk.ac.ebi.masscascade.knime.featurebuilding.tracejoiner; import org.knime.core.node.NodeDialogPane; import org.knime.core.node.NodeFactory; import org.knime.core.node.NodeView; import uk.ac.ebi.masscascade.knime.datatypes.featurecell.FeatureValue; import uk.ac.ebi.masscascade.knime.defaults.DefaultDialog; import uk.ac.ebi.masscascade.parameters.Parameter; /** * <code>NodeFactory</code> for the "MassTraceCompiler" Node. Compiles whole chromatogram mass traces from a given set * of peaks. Identical masses within a predefined tolerance range are merged into one extracted ion chromatogram. * * @author Stephan Beisken */ @Deprecated public class MassTraceCompilerNodeFactory extends NodeFactory<MassTraceCompilerNodeModel> { /** * {@inheritDoc} */ @Override public MassTraceCompilerNodeModel createNodeModel() { return new MassTraceCompilerNodeModel(); } /** * {@inheritDoc} */ @Override public int getNrNodeViews() { return 0; } /** * {@inheritDoc} */ @Override public NodeView<MassTraceCompilerNodeModel> createNodeView(final int viewIndex, final MassTraceCompilerNodeModel nodeModel) { return null; } /** * {@inheritDoc} */ @Override public boolean hasDialog() { return true; } /** * {@inheritDoc} */ @Override public NodeDialogPane createNodeDialogPane() { DefaultDialog dialog = new DefaultDialog(); dialog.addColumnSelection(Parameter.FEATURE_COLUMN, FeatureValue.class); dialog.addTextOption(Parameter.MZ_WINDOW_PPM, 5); return dialog.build(); } }
tomas-pluskal/masscascadeknime
src/uk/ac/ebi/masscascade/knime/featurebuilding/tracejoiner/MassTraceCompilerNodeFactory.java
Java
gpl-3.0
2,404
/******************************************************************************* * | o | * | o o | HELYX-OS: The Open Source GUI for OpenFOAM | * | o O o | Copyright (C) 2012-2016 ENGYS | * | o o | http://www.engys.com | * | o | | * |---------------------------------------------------------------------------| * | License | * | This file is part of HELYX-OS. | * | | * | HELYX-OS is free software; you can redistribute it and/or modify it | * | under the terms of the GNU General Public License as published by the | * | Free Software Foundation; either version 2 of the License, or (at your | * | option) any later version. | * | | * | HELYX-OS is distributed in the hope that it will be useful, but WITHOUT | * | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | * | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | * | for more details. | * | | * | You should have received a copy of the GNU General Public License | * | along with HELYX-OS; if not, write to the Free Software Foundation, | * | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | *******************************************************************************/ package eu.engys.core.project.geometry.surface; import static eu.engys.core.dictionary.Dictionary.TYPE; import java.util.Arrays; import org.apache.commons.lang.ArrayUtils; import eu.engys.core.dictionary.Dictionary; import eu.engys.core.project.geometry.Surface; import eu.engys.core.project.geometry.Type; import vtk.vtkLineSource; import vtk.vtkPolyData; import vtk.vtkTubeFilter; public class Cylinder extends BaseSurface { public static final double[] DEFAULT_P1 = {0,0,0}; public static final double[] DEFAULT_P2 = {1,0,0}; public static final double DEFAULT_RADIUS = 1.0; private double[] point1 = DEFAULT_P1; private double[] point2 = DEFAULT_P2; private double radius = DEFAULT_RADIUS; public static final Dictionary cylinder = new Dictionary("cylinder") { { add(TYPE, Surface.SEARCHABLE_CYLINDER_KEY); add(Surface.POINT1_KEY, "(0 0 0)"); add(Surface.POINT2_KEY, "(1 0 0)"); add(Surface.RADIUS_KEY, "1.0"); } }; /** * @deprecated Use GeometryFactory!! */ @Deprecated public Cylinder(String name) { super(name); } @Override public Type getType() { return Type.CYLINDER; } public double[] getPoint1() { return point1; } public void setPoint1(double[] point1) { firePropertyChange("point1", this.point1, this.point1 = point1); } public void setPoint1(double d1, double d2, double d3) { setPoint1(new double[]{d1,d2,d3}); } public double[] getPoint2() { return point2; } public void setPoint2(double[] point2) { firePropertyChange("point2", this.point2, this.point2 = point2); } public void setPoint2(double d1, double d2, double d3) { setPoint2(new double[]{d1,d2,d3}); } public double getRadius() { return radius; } public void setRadius(double radius) { firePropertyChange("radius", this.radius, this.radius = radius); } @Override public Surface cloneSurface() { Cylinder cyl = new Cylinder(name); cyl.point1 = ArrayUtils.clone(point1); cyl.point2 = ArrayUtils.clone(point2); cyl.radius = radius; cloneSurface(cyl); return cyl; } @Override public void copyFrom(Surface delegate, boolean changeGeometry, boolean changeSurface, boolean changeVolume, boolean changeLayer, boolean changeZone) { if (delegate instanceof Cylinder) { Cylinder cyl = (Cylinder) delegate; if (changeGeometry) { setPoint1(cyl.getPoint1()); setPoint2(cyl.getPoint2()); setRadius(cyl.getRadius()); } super.copyFrom(delegate, changeGeometry, changeSurface, changeVolume, changeLayer, changeZone); } } @Override public vtkPolyData getDataSet() { double[] point1 = getPoint1(); double[] point2 = getPoint2(); double radius = getRadius(); vtkLineSource lineSource = new vtkLineSource(); lineSource.SetPoint1(point1); lineSource.SetPoint2(point2); // Create a tube (cylinder) around the line vtkTubeFilter tubeFilter = new vtkTubeFilter(); tubeFilter.SetInputConnection(lineSource.GetOutputPort()); tubeFilter.SetCapping(1); tubeFilter.SetRadius(radius); tubeFilter.SetNumberOfSides(50); tubeFilter.Update(); return tubeFilter.GetOutput(); } @Override public Dictionary toGeometryDictionary() { Dictionary d = new Dictionary(name, cylinder); d.add(POINT1_KEY, point1); d.add(POINT2_KEY, point2); d.add(RADIUS_KEY, radius); return d; } @Override public void fromGeometryDictionary(Dictionary g) { if (g != null && g.found(TYPE) && g.lookup(TYPE).equals(SEARCHABLE_CYLINDER_KEY) ) { if (g.found(POINT1_KEY)) setPoint1(g.lookupDoubleArray(POINT1_KEY)); else setPoint1(DEFAULT_P1); if (g.found(POINT2_KEY)) setPoint2(g.lookupDoubleArray(POINT2_KEY)); else setPoint2(DEFAULT_P2); if (g.found(RADIUS_KEY)) setRadius(g.lookupDouble(RADIUS_KEY)); else setRadius(DEFAULT_RADIUS); } } @Override public String toString() { String string = super.toString(); return string + String.format("[ p1: %s, p2: %s, radius: %s] ", Arrays.toString(point1), Arrays.toString(point2), radius); } }
ENGYS/HELYX-OS
src/eu/engys/core/project/geometry/surface/Cylinder.java
Java
gpl-3.0
6,610
// ReSharper disable All using System.Collections.Generic; using System.Dynamic; using System.Net; using System.Net.Http; using System.Web.Http; using MixERP.Net.Api.Framework; using MixERP.Net.ApplicationState.Cache; using MixERP.Net.Common.Extensions; using MixERP.Net.EntityParser; using MixERP.Net.Framework; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PetaPoco; using MixERP.Net.Schemas.Core.Data; namespace MixERP.Net.Api.Core { /// <summary> /// Provides a direct HTTP access to perform various tasks such as adding, editing, and removing Price Types. /// </summary> [RoutePrefix("api/v1.5/core/price-type")] public class PriceTypeController : ApiController { /// <summary> /// The PriceType repository. /// </summary> private readonly IPriceTypeRepository PriceTypeRepository; public PriceTypeController() { this._LoginId = AppUsers.GetCurrent().View.LoginId.ToLong(); this._UserId = AppUsers.GetCurrent().View.UserId.ToInt(); this._OfficeId = AppUsers.GetCurrent().View.OfficeId.ToInt(); this._Catalog = AppUsers.GetCurrentUserDB(); this.PriceTypeRepository = new MixERP.Net.Schemas.Core.Data.PriceType { _Catalog = this._Catalog, _LoginId = this._LoginId, _UserId = this._UserId }; } public PriceTypeController(IPriceTypeRepository repository, string catalog, LoginView view) { this._LoginId = view.LoginId.ToLong(); this._UserId = view.UserId.ToInt(); this._OfficeId = view.OfficeId.ToInt(); this._Catalog = catalog; this.PriceTypeRepository = repository; } public long _LoginId { get; } public int _UserId { get; private set; } public int _OfficeId { get; private set; } public string _Catalog { get; } /// <summary> /// Creates meta information of "price type" entity. /// </summary> /// <returns>Returns the "price type" meta information to perform CRUD operation.</returns> [AcceptVerbs("GET", "HEAD")] [Route("meta")] [Route("~/api/core/price-type/meta")] public EntityView GetEntityView() { if (this._LoginId == 0) { return new EntityView(); } return new EntityView { PrimaryKey = "price_type_id", Columns = new List<EntityColumn>() { new EntityColumn { ColumnName = "price_type_id", PropertyName = "PriceTypeId", DataType = "int", DbDataType = "int4", IsNullable = false, IsPrimaryKey = true, IsSerial = true, Value = "", MaxLength = 0 }, new EntityColumn { ColumnName = "price_type_code", PropertyName = "PriceTypeCode", DataType = "string", DbDataType = "varchar", IsNullable = false, IsPrimaryKey = false, IsSerial = false, Value = "", MaxLength = 12 }, new EntityColumn { ColumnName = "price_type_name", PropertyName = "PriceTypeName", DataType = "string", DbDataType = "varchar", IsNullable = false, IsPrimaryKey = false, IsSerial = false, Value = "", MaxLength = 50 }, new EntityColumn { ColumnName = "audit_user_id", PropertyName = "AuditUserId", DataType = "int", DbDataType = "int4", IsNullable = true, IsPrimaryKey = false, IsSerial = false, Value = "", MaxLength = 0 }, new EntityColumn { ColumnName = "audit_ts", PropertyName = "AuditTs", DataType = "DateTime", DbDataType = "timestamptz", IsNullable = true, IsPrimaryKey = false, IsSerial = false, Value = "", MaxLength = 0 } } }; } /// <summary> /// Counts the number of price types. /// </summary> /// <returns>Returns the count of the price types.</returns> [AcceptVerbs("GET", "HEAD")] [Route("count")] [Route("~/api/core/price-type/count")] public long Count() { try { return this.PriceTypeRepository.Count(); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Returns all collection of price type. /// </summary> /// <returns></returns> [AcceptVerbs("GET", "HEAD")] [Route("all")] [Route("~/api/core/price-type/all")] public IEnumerable<MixERP.Net.Entities.Core.PriceType> GetAll() { try { return this.PriceTypeRepository.GetAll(); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Returns collection of price type for export. /// </summary> /// <returns></returns> [AcceptVerbs("GET", "HEAD")] [Route("export")] [Route("~/api/core/price-type/export")] public IEnumerable<dynamic> Export() { try { return this.PriceTypeRepository.Export(); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Returns an instance of price type. /// </summary> /// <param name="priceTypeId">Enter PriceTypeId to search for.</param> /// <returns></returns> [AcceptVerbs("GET", "HEAD")] [Route("{priceTypeId}")] [Route("~/api/core/price-type/{priceTypeId}")] public MixERP.Net.Entities.Core.PriceType Get(int priceTypeId) { try { return this.PriceTypeRepository.Get(priceTypeId); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } [AcceptVerbs("GET", "HEAD")] [Route("get")] [Route("~/api/core/price-type/get")] public IEnumerable<MixERP.Net.Entities.Core.PriceType> Get([FromUri] int[] priceTypeIds) { try { return this.PriceTypeRepository.Get(priceTypeIds); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Creates a paginated collection containing 10 price types on each page, sorted by the property PriceTypeId. /// </summary> /// <returns>Returns the first page from the collection.</returns> [AcceptVerbs("GET", "HEAD")] [Route("")] [Route("~/api/core/price-type")] public IEnumerable<MixERP.Net.Entities.Core.PriceType> GetPaginatedResult() { try { return this.PriceTypeRepository.GetPaginatedResult(); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Creates a paginated collection containing 10 price types on each page, sorted by the property PriceTypeId. /// </summary> /// <param name="pageNumber">Enter the page number to produce the resultset.</param> /// <returns>Returns the requested page from the collection.</returns> [AcceptVerbs("GET", "HEAD")] [Route("page/{pageNumber}")] [Route("~/api/core/price-type/page/{pageNumber}")] public IEnumerable<MixERP.Net.Entities.Core.PriceType> GetPaginatedResult(long pageNumber) { try { return this.PriceTypeRepository.GetPaginatedResult(pageNumber); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Counts the number of price types using the supplied filter(s). /// </summary> /// <param name="filters">The list of filter conditions.</param> /// <returns>Returns the count of filtered price types.</returns> [AcceptVerbs("POST")] [Route("count-where")] [Route("~/api/core/price-type/count-where")] public long CountWhere([FromBody]JArray filters) { try { List<EntityParser.Filter> f = filters.ToObject<List<EntityParser.Filter>>(JsonHelper.GetJsonSerializer()); return this.PriceTypeRepository.CountWhere(f); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Creates a filtered and paginated collection containing 10 price types on each page, sorted by the property PriceTypeId. /// </summary> /// <param name="pageNumber">Enter the page number to produce the resultset. If you provide a negative number, the result will not be paginated.</param> /// <param name="filters">The list of filter conditions.</param> /// <returns>Returns the requested page from the collection using the supplied filters.</returns> [AcceptVerbs("POST")] [Route("get-where/{pageNumber}")] [Route("~/api/core/price-type/get-where/{pageNumber}")] public IEnumerable<MixERP.Net.Entities.Core.PriceType> GetWhere(long pageNumber, [FromBody]JArray filters) { try { List<EntityParser.Filter> f = filters.ToObject<List<EntityParser.Filter>>(JsonHelper.GetJsonSerializer()); return this.PriceTypeRepository.GetWhere(pageNumber, f); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Counts the number of price types using the supplied filter name. /// </summary> /// <param name="filterName">The named filter.</param> /// <returns>Returns the count of filtered price types.</returns> [AcceptVerbs("GET", "HEAD")] [Route("count-filtered/{filterName}")] [Route("~/api/core/price-type/count-filtered/{filterName}")] public long CountFiltered(string filterName) { try { return this.PriceTypeRepository.CountFiltered(filterName); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Creates a filtered and paginated collection containing 10 price types on each page, sorted by the property PriceTypeId. /// </summary> /// <param name="pageNumber">Enter the page number to produce the resultset. If you provide a negative number, the result will not be paginated.</param> /// <param name="filterName">The named filter.</param> /// <returns>Returns the requested page from the collection using the supplied filters.</returns> [AcceptVerbs("GET", "HEAD")] [Route("get-filtered/{pageNumber}/{filterName}")] [Route("~/api/core/price-type/get-filtered/{pageNumber}/{filterName}")] public IEnumerable<MixERP.Net.Entities.Core.PriceType> GetFiltered(long pageNumber, string filterName) { try { return this.PriceTypeRepository.GetFiltered(pageNumber, filterName); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Displayfield is a lightweight key/value collection of price types. /// </summary> /// <returns>Returns an enumerable key/value collection of price types.</returns> [AcceptVerbs("GET", "HEAD")] [Route("display-fields")] [Route("~/api/core/price-type/display-fields")] public IEnumerable<DisplayField> GetDisplayFields() { try { return this.PriceTypeRepository.GetDisplayFields(); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// A custom field is a user defined field for price types. /// </summary> /// <returns>Returns an enumerable custom field collection of price types.</returns> [AcceptVerbs("GET", "HEAD")] [Route("custom-fields")] [Route("~/api/core/price-type/custom-fields")] public IEnumerable<PetaPoco.CustomField> GetCustomFields() { try { return this.PriceTypeRepository.GetCustomFields(null); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// A custom field is a user defined field for price types. /// </summary> /// <returns>Returns an enumerable custom field collection of price types.</returns> [AcceptVerbs("GET", "HEAD")] [Route("custom-fields/{resourceId}")] [Route("~/api/core/price-type/custom-fields/{resourceId}")] public IEnumerable<PetaPoco.CustomField> GetCustomFields(string resourceId) { try { return this.PriceTypeRepository.GetCustomFields(resourceId); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Adds or edits your instance of PriceType class. /// </summary> /// <param name="priceType">Your instance of price types class to add or edit.</param> [AcceptVerbs("POST")] [Route("add-or-edit")] [Route("~/api/core/price-type/add-or-edit")] public object AddOrEdit([FromBody]Newtonsoft.Json.Linq.JArray form) { dynamic priceType = form[0].ToObject<ExpandoObject>(JsonHelper.GetJsonSerializer()); List<EntityParser.CustomField> customFields = form[1].ToObject<List<EntityParser.CustomField>>(JsonHelper.GetJsonSerializer()); if (priceType == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MethodNotAllowed)); } try { return this.PriceTypeRepository.AddOrEdit(priceType, customFields); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Adds your instance of PriceType class. /// </summary> /// <param name="priceType">Your instance of price types class to add.</param> [AcceptVerbs("POST")] [Route("add/{priceType}")] [Route("~/api/core/price-type/add/{priceType}")] public void Add(MixERP.Net.Entities.Core.PriceType priceType) { if (priceType == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MethodNotAllowed)); } try { this.PriceTypeRepository.Add(priceType); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Edits existing record with your instance of PriceType class. /// </summary> /// <param name="priceType">Your instance of PriceType class to edit.</param> /// <param name="priceTypeId">Enter the value for PriceTypeId in order to find and edit the existing record.</param> [AcceptVerbs("PUT")] [Route("edit/{priceTypeId}")] [Route("~/api/core/price-type/edit/{priceTypeId}")] public void Edit(int priceTypeId, [FromBody] MixERP.Net.Entities.Core.PriceType priceType) { if (priceType == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MethodNotAllowed)); } try { this.PriceTypeRepository.Update(priceType, priceTypeId); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } private List<ExpandoObject> ParseCollection(JArray collection) { return JsonConvert.DeserializeObject<List<ExpandoObject>>(collection.ToString(), JsonHelper.GetJsonSerializerSettings()); } /// <summary> /// Adds or edits multiple instances of PriceType class. /// </summary> /// <param name="collection">Your collection of PriceType class to bulk import.</param> /// <returns>Returns list of imported priceTypeIds.</returns> /// <exception cref="MixERPException">Thrown when your any PriceType class in the collection is invalid or malformed.</exception> [AcceptVerbs("POST")] [Route("bulk-import")] [Route("~/api/core/price-type/bulk-import")] public List<object> BulkImport([FromBody]JArray collection) { List<ExpandoObject> priceTypeCollection = this.ParseCollection(collection); if (priceTypeCollection == null || priceTypeCollection.Count.Equals(0)) { return null; } try { return this.PriceTypeRepository.BulkImport(priceTypeCollection); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } /// <summary> /// Deletes an existing instance of PriceType class via PriceTypeId. /// </summary> /// <param name="priceTypeId">Enter the value for PriceTypeId in order to find and delete the existing record.</param> [AcceptVerbs("DELETE")] [Route("delete/{priceTypeId}")] [Route("~/api/core/price-type/delete/{priceTypeId}")] public void Delete(int priceTypeId) { try { this.PriceTypeRepository.Delete(priceTypeId); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (MixERPException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } } } }
gguruss/mixerp
src/Libraries/Web API/Core/PriceTypeController.cs
C#
gpl-3.0
28,610
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// /** * get name of month * \param[in] month_num number of month * \param[in] flag_simple flag_simple * \return name of month */ function libcore__getmonthname($month_num, $flag_simple = false) { if ($flag_simple === false) { if ($month_num === 1) return 'января'; if ($month_num === 2) return 'февраля'; if ($month_num === 3) return 'марта'; if ($month_num === 4) return 'апреля'; if ($month_num === 5) return 'мая'; if ($month_num === 6) return 'июня'; if ($month_num === 7) return 'июля'; if ($month_num === 8) return 'августа'; if ($month_num === 9) return 'сентября'; if ($month_num === 10) return 'октября'; if ($month_num === 11) return 'ноября'; if ($month_num === 12) return 'декабря'; return 'мартобря'; } if ($month_num === 1) return 'Январь'; if ($month_num === 2) return 'Февраль'; if ($month_num === 3) return 'Март'; if ($month_num === 4) return 'Апрель'; if ($month_num === 5) return 'Май'; if ($month_num === 6) return 'Июнь'; if ($month_num === 7) return 'Июль'; if ($month_num === 8) return 'Август'; if ($month_num === 9) return 'Сентябрь'; if ($month_num === 10) return 'Октябрь'; if ($month_num === 11) return 'Ноябрь'; if ($month_num === 12) return 'Декабрь'; return 'Мартобрь'; } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
progman/libcore.php
src/function/time/!whitout_test/libcore__getmonthname/libcore__getmonthname.php
PHP
gpl-3.0
2,049
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using StoresAndInventoryManager.Classes; namespace StoresAndInventoryManager.Forms { public partial class pymntsRcvdForm : Form { //Transactions Search private long totl_trns = 0; private long cur_trns_idx = 0; public string trnsDet_SQL = ""; private bool is_last_trns = false; bool obeytrnsEvnts = false; long last_trns_num = 0; public pymntsRcvdForm() { InitializeComponent(); } #region "TRANSACTIONS SEARCH..." public void loadTrnsPanel() { this.obeytrnsEvnts = false; if (this.searchInTrnsComboBox.SelectedIndex < 0) { this.searchInTrnsComboBox.SelectedIndex = 1; } int dsply = 0; if (this.dsplySizeTrnsComboBox.Text == "" || int.TryParse(this.dsplySizeTrnsComboBox.Text, out dsply) == false) { this.dsplySizeTrnsComboBox.Text = Global.mnFrm.cmCde.get_CurPlcy_Mx_Dsply_Recs().ToString(); } if (this.searchForTrnsTextBox.Text == "") { this.searchForTrnsTextBox.Text = "%"; } this.is_last_trns = false; this.totl_trns = Global.mnFrm.cmCde.Big_Val; this.getTrnsPnlData(); this.obeytrnsEvnts = true; } private void getTrnsPnlData() { this.updtTrnsTotals(); this.populateTrnsGridVw(); this.updtTrnsNavLabels(); } private void updtTrnsTotals() { Global.mnFrm.cmCde.navFuncts.FindNavigationIndices( int.Parse(this.dsplySizeTrnsComboBox.Text), this.totl_trns); if (this.cur_trns_idx >= Global.mnFrm.cmCde.navFuncts.totalGroups) { this.cur_trns_idx = Global.mnFrm.cmCde.navFuncts.totalGroups - 1; } if (this.cur_trns_idx < 0) { this.cur_trns_idx = 0; } Global.mnFrm.cmCde.navFuncts.currentNavigationIndex = this.cur_trns_idx; } private void updtTrnsNavLabels() { this.moveFirstTrnsButton.Enabled = Global.mnFrm.cmCde.navFuncts.moveFirstBtnStatus(); this.movePreviousTrnsButton.Enabled = Global.mnFrm.cmCde.navFuncts.movePrevBtnStatus(); this.moveNextTrnsButton.Enabled = Global.mnFrm.cmCde.navFuncts.moveNextBtnStatus(); this.moveLastTrnsButton.Enabled = Global.mnFrm.cmCde.navFuncts.moveLastBtnStatus(); this.positionTrnsTextBox.Text = Global.mnFrm.cmCde.navFuncts.displayedRecordsNumbers(); if (this.is_last_trns == true || this.totl_trns != Global.mnFrm.cmCde.Big_Val) { this.totalRecsTrnsLabel.Text = Global.mnFrm.cmCde.navFuncts.totalRecordsLabel(); } else { this.totalRecsTrnsLabel.Text = "of Total"; } } private void populateTrnsGridVw() { this.obeytrnsEvnts = false; DataSet dtst; dtst = Global.get_ScmPay_Trns(this.searchForTrnsTextBox.Text, this.searchInTrnsComboBox.Text, this.cur_trns_idx, int.Parse(this.dsplySizeTrnsComboBox.Text), Global.mnFrm.cmCde.Org_id, this.vldStrtDteTextBox.Text, this.vldEndDteTextBox.Text); this.trnsSearchListView.Items.Clear(); for (int i = 0; i < dtst.Tables[0].Rows.Count; i++) { string amntRcvd = "0.00"; if (double.Parse(dtst.Tables[0].Rows[i][2].ToString()) > 0 && double.Parse(dtst.Tables[0].Rows[i][3].ToString()) <= 0) { amntRcvd = (Math.Abs(double.Parse(dtst.Tables[0].Rows[i][2].ToString())) - double.Parse(dtst.Tables[0].Rows[i][3].ToString())).ToString("#,##0.00"); } else if (double.Parse(dtst.Tables[0].Rows[i][2].ToString()) > 0 && double.Parse(dtst.Tables[0].Rows[i][3].ToString()) > 0) { amntRcvd = double.Parse(dtst.Tables[0].Rows[i][2].ToString()).ToString("#,##0.00"); } this.last_trns_num = Global.mnFrm.cmCde.navFuncts.startIndex() + i; ListViewItem nwItem = new ListViewItem(new string[] { (Global.mnFrm.cmCde.navFuncts.startIndex() + i).ToString(), dtst.Tables[0].Rows[i][5].ToString(), dtst.Tables[0].Rows[i][9].ToString(), dtst.Tables[0].Rows[i][1].ToString(), amntRcvd, double.Parse(dtst.Tables[0].Rows[i][2].ToString()).ToString("#,##0.00"), double.Parse(dtst.Tables[0].Rows[i][3].ToString()).ToString("#,##0.00"), dtst.Tables[0].Rows[i][8].ToString(), dtst.Tables[0].Rows[i][4].ToString(), dtst.Tables[0].Rows[i][6].ToString(), dtst.Tables[0].Rows[i][0].ToString(), dtst.Tables[0].Rows[i][10].ToString()}); this.trnsSearchListView.Items.Add(nwItem); } /* Global.get_GLBatch_Nm(long.Parse(dtst.Tables[0].Rows[i][8].ToString())),*/ this.correctTrnsNavLbls(dtst); this.obeytrnsEvnts = true; } private void correctTrnsNavLbls(DataSet dtst) { long totlRecs = dtst.Tables[0].Rows.Count; if (this.cur_trns_idx == 0 && totlRecs == 0) { this.is_last_trns = true; this.totl_trns = 0; this.last_trns_num = 0; this.cur_trns_idx = 0; this.updtTrnsTotals(); this.updtTrnsNavLabels(); } else if (this.totl_trns == Global.mnFrm.cmCde.Big_Val && totlRecs < long.Parse(this.dsplySizeTrnsComboBox.Text)) { this.totl_trns = this.last_trns_num; if (totlRecs == 0) { this.cur_trns_idx -= 1; this.updtTrnsTotals(); this.populateTrnsGridVw(); } else { this.updtTrnsTotals(); } } } private void TrnsPnlNavButtons(object sender, System.EventArgs e) { System.Windows.Forms.ToolStripButton sentObj = (System.Windows.Forms.ToolStripButton)sender; this.totalRecsTrnsLabel.Text = ""; if (sentObj.Name.ToLower().Contains("first")) { this.cur_trns_idx = 0; } else if (sentObj.Name.ToLower().Contains("previous")) { this.cur_trns_idx -= 1; } else if (sentObj.Name.ToLower().Contains("next")) { this.cur_trns_idx += 1; } else if (sentObj.Name.ToLower().Contains("last")) { this.totl_trns = Global.get_Total_ScmTrns( this.searchForTrnsTextBox.Text, this.searchInTrnsComboBox.Text, Global.mnFrm.cmCde.Org_id, this.vldStrtDteTextBox.Text, this.vldEndDteTextBox.Text); this.is_last_trns = true; this.updtTrnsTotals(); this.cur_trns_idx = Global.mnFrm.cmCde.navFuncts.totalGroups - 1; } this.getTrnsPnlData(); } private void dte1Button_Click(object sender, EventArgs e) { Global.mnFrm.cmCde.selectDate(ref this.vldStrtDteTextBox); } private void dte2Button_Click(object sender, EventArgs e) { Global.mnFrm.cmCde.selectDate(ref this.vldEndDteTextBox); } private void goTrnsButton_Click(object sender, EventArgs e) { this.loadTrnsPanel(); } private void exptPySrchMenuItem_Click(object sender, EventArgs e) { Global.mnFrm.cmCde.exprtToExcel(this.trnsSearchListView); } private void positionTrnsTextBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { EventArgs ex = new EventArgs(); if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Up) { this.TrnsPnlNavButtons(this.movePreviousTrnsButton, ex); } else if (e.KeyCode == Keys.Right || e.KeyCode == Keys.Down) { this.TrnsPnlNavButtons(this.moveNextTrnsButton, ex); } } private void searchForTrnsTextBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { EventArgs ex = new EventArgs(); if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) { this.goTrnsButton_Click(this.goTrnsButton, ex); } } private void vwSQLTrnsButton_Click(object sender, EventArgs e) { Global.mnFrm.cmCde.showSQL(Global.mnFrm.trnsDet_SQL, 9); } private void recHstryTrnsButton_Click(object sender, EventArgs e) { if (this.trnsSearchListView.SelectedItems.Count <= 0) { Global.mnFrm.cmCde.showMsg("Please select a Record First!", 0); return; } Global.mnFrm.cmCde.showRecHstry( Global.mnFrm.cmCde.get_Gnrl_Rec_Hstry(long.Parse( this.trnsSearchListView.SelectedItems[0].SubItems[9].Text), "scm.scm_payments", "pymnt_id"), 10); } private void rfrshPySrchMenuItem_Click(object sender, EventArgs e) { this.goTrnsButton_Click(this.goTrnsButton, e); } private void vwSQLPySrchMenuItem_Click(object sender, EventArgs e) { this.vwSQLTrnsButton_Click(this.vwSQLTrnsButton, e); } private void rcHstryPySrchMenuItem_Click(object sender, EventArgs e) { this.recHstryTrnsButton_Click(this.recHstryTrnsButton, e); } #endregion private void pymntsRcvdForm_Load(object sender, EventArgs e) { Color[] clrs = Global.mnFrm.cmCde.getColors(); this.BackColor = clrs[0]; this.glsLabel2.TopFill = clrs[0]; this.glsLabel2.BottomFill = clrs[1]; this.vldStrtDteTextBox.Text = DateTime.Parse(Global.mnFrm.cmCde.getDB_Date_time()).AddMonths(-24).ToString("dd-MMM-yyyy HH:mm:ss"); this.vldEndDteTextBox.Text = DateTime.Parse(Global.mnFrm.cmCde.getDB_Date_time()).AddDays(1).ToString("dd-MMM-yyyy 00:00:00"); } private void rvrsPymntButton_Click(object sender, EventArgs e) { int dfltRcvblAcntID = Global.get_DfltRcvblAcnt(Global.mnFrm.cmCde.Org_id); int dfltCashAcntID = Global.get_DfltCashAcnt(Global.mnFrm.cmCde.Org_id); int dfltCheckAcntID = Global.get_DfltCheckAcnt(Global.mnFrm.cmCde.Org_id); if (dfltRcvblAcntID <= 0 || dfltCashAcntID <= 0 || dfltCheckAcntID <= 0) { Global.mnFrm.cmCde.showMsg("You must first Setup all Default " + "Accounts before Accounting Transactions can be Created!", 0); return; } if (Global.mnFrm.cmCde.showMsg("Are you sure you want to REVERSE this Payment?" + "\r\nThis action cannot be undone!", 1) == DialogResult.No) { Global.mnFrm.cmCde.showMsg("Operation Cancelled!", 4); return; } double netAmnt = 0; double amntPaid = double.Parse(this.trnsSearchListView.SelectedItems[0].SubItems[5].Text); long docHdrID = long.Parse(this.trnsSearchListView.SelectedItems[0].SubItems[9].Text); string docTyp = this.trnsSearchListView.SelectedItems[0].SubItems[1].Text; string dteRcvd = this.trnsSearchListView.SelectedItems[0].SubItems[7].Text; if (dteRcvd.Length <= 11) { dteRcvd = dteRcvd + " 12:00:00"; } double grndTotl = Global.get_DocSmryGrndTtl(docHdrID, docTyp); string pyTyp = this.trnsSearchListView.SelectedItems[0].SubItems[3].Text; string pyDesc = this.trnsSearchListView.SelectedItems[0].SubItems[8].Text; netAmnt = -1 * amntPaid; //if (amntPaid < grndTotl) //{ //} //else //{ // netAmnt = (amntPaid + this.changeNumUpDown.Value); //} string dateStr = DateTime.ParseExact( Global.mnFrm.cmCde.getDB_Date_time(), "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MMM-yyyy HH:mm:ss"); long pymntID = Global.getPymntRcvdID(docHdrID, docTyp, dteRcvd, netAmnt); double outsBals = Global.get_DocSmryOutsbls(docHdrID, docTyp); if (outsBals < grndTotl) { Global.createPaymntLine(pyTyp, netAmnt, 0.00, "(Reversal) " + pyDesc, docTyp, docHdrID, dateStr, dteRcvd); } else { Global.mnFrm.cmCde.showMsg("No Payment is available for Reversal!", 0); return; } bool succs = false; pymntID = Global.getPymntRcvdID(docHdrID, docTyp, dteRcvd, netAmnt); int crncyID = Global.mnFrm.cmCde.getOrgFuncCurID(Global.mnFrm.cmCde.Org_id); if (docTyp == "Sales Invoice") { if (this.isPayTrnsValid(dfltRcvblAcntID, "D", netAmnt, dteRcvd)) { succs = this.sendToGLInterfaceMnl(dfltRcvblAcntID, "D", netAmnt, dteRcvd, "(Reversal) Payment received for Sales made", crncyID, dateStr, docTyp + " (Payment Reversal)", docHdrID, pymntID); if (!succs) { Global.mnFrm.cmCde.showMsg("Failed to Send Payment to GL Interface!", 0); this.undoPayment(pymntID, docHdrID, docTyp); return; } } else { this.undoPayment(pymntID, docHdrID, docTyp); return; } if (pyTyp == "Cash") { if (this.isPayTrnsValid(dfltCashAcntID, "I", netAmnt, dteRcvd)) { succs = this.sendToGLInterfaceMnl(dfltCashAcntID, "I", netAmnt, dteRcvd, "(Reversal) Payment received for Sales made", crncyID, dateStr, docTyp + " (Payment Reversal)", docHdrID, pymntID); if (!succs) { Global.mnFrm.cmCde.showMsg("Failed to Send Payment to GL Interface!", 0); this.undoPayment(pymntID, docHdrID, docTyp); return; } } else { this.undoPayment(pymntID, docHdrID, docTyp); return; } } else { if (this.isPayTrnsValid(dfltCheckAcntID, "I", netAmnt, dteRcvd)) { succs = this.sendToGLInterfaceMnl(dfltCheckAcntID, "I", netAmnt, dteRcvd, "(Reversal) Payment received for Sales made", crncyID, dateStr, docTyp + " (Payment Reversal)", docHdrID, pymntID); if (!succs) { Global.mnFrm.cmCde.showMsg("Failed to Send Payment to GL Interface!", 0); this.undoPayment(pymntID, docHdrID, docTyp); return; } } else { this.undoPayment(pymntID, docHdrID, docTyp); return; } } } else if (docTyp == "Sales Return") { if (this.isPayTrnsValid(dfltRcvblAcntID, "I", netAmnt, dteRcvd)) { succs = this.sendToGLInterfaceMnl(dfltRcvblAcntID, "I", netAmnt, dteRcvd, "(Reversal) Payment of Refund for Sales Returned", crncyID, dateStr, docTyp + " (Payment)", docHdrID, pymntID); if (!succs) { Global.mnFrm.cmCde.showMsg("Failed to Send Payment to GL Interface!", 0); this.undoPayment(pymntID, docHdrID, docTyp); return; } } else { this.undoPayment(pymntID, docHdrID, docTyp); return; } if (pyTyp == "Cash") { if (this.isPayTrnsValid(dfltCashAcntID, "D", netAmnt, dteRcvd)) { succs = this.sendToGLInterfaceMnl(dfltCashAcntID, "D", netAmnt, dteRcvd, "(Reversal) Payment of Refund for Sales Returned", crncyID, dateStr, docTyp + " (Payment)", docHdrID, pymntID); if (!succs) { Global.mnFrm.cmCde.showMsg("Failed to Send Payment to GL Interface!", 0); this.undoPayment(pymntID, docHdrID, docTyp); return; } } else { this.undoPayment(pymntID, docHdrID, docTyp); return; } } else { if (this.isPayTrnsValid(dfltCheckAcntID, "D", netAmnt, dteRcvd)) { succs = this.sendToGLInterfaceMnl(dfltCheckAcntID, "D", netAmnt, dteRcvd, "(Reversal) Payment of Refund for Sales Returned", crncyID, dateStr, docTyp + "(Payment)", docHdrID, pymntID); if (!succs) { Global.mnFrm.cmCde.showMsg("Failed to Send Payment to GL Interface!", 0); this.undoPayment(pymntID, docHdrID, docTyp); return; } } else { this.undoPayment(pymntID, docHdrID, docTyp); return; } } } this.reCalcSmmrys(docHdrID, docTyp); this.goTrnsButton_Click(this.goTrnsButton, e); } public void undoPayment(long pymntID, long docHdrID, string docTyp) { Global.deletePymntLn(pymntID); Global.deletePymtGLInfcLns(docHdrID, docTyp, pymntID); EventArgs e = new EventArgs(); this.reCalcSmmrys(docHdrID, docTyp); this.goTrnsButton_Click(this.goTrnsButton, e); } public void reCalcSmmrys(long srcDocID, string srcDocType) { DataSet dtst = Global.get_One_SalesDcLines(srcDocID); double grndAmnt = Global.getSalesDocGrndAmnt(srcDocID); // Grand Total string smmryNm = "Grand Total"; long smmryID = Global.getSalesSmmryItmID("5Grand Total", -1, srcDocID, srcDocType); if (smmryID <= 0) { Global.createSmmryItm("5Grand Total", smmryNm, grndAmnt, -1, srcDocType, srcDocID, true); } else { Global.updateSmmryItm(smmryID, "5Grand Total", grndAmnt, true, smmryNm); } //Total Payments double blsAmnt = 0; double pymntsAmnt = 0; long SIDocID = -1; long.TryParse(Global.mnFrm.cmCde.getGnrlRecNm("scm.scm_sales_invc_hdr", "invc_hdr_id", "src_doc_hdr_id", srcDocID), out SIDocID); string strSrcDocType = Global.mnFrm.cmCde.getGnrlRecNm("scm.scm_sales_invc_hdr", "invc_hdr_id", "invc_type", SIDocID); if (srcDocType == "Sales Invoice") { pymntsAmnt = Global.getSalesDocRcvdPymnts(srcDocID, srcDocType); smmryNm = "Total Payments Received"; smmryID = Global.getSalesSmmryItmID("6Total Payments Received", -1, srcDocID, srcDocType); if (smmryID <= 0) { Global.createSmmryItm("6Total Payments Received", smmryNm, pymntsAmnt, -1, srcDocType, srcDocID, true); } else { Global.updateSmmryItm(smmryID, "6Total Payments Received", pymntsAmnt, true, smmryNm); } } else if (srcDocType == "Sales Return" && strSrcDocType == "Sales Invoice") { pymntsAmnt = Global.getSalesDocRcvdPymnts(srcDocID, srcDocType); smmryNm = "Total Amount Refunded"; smmryID = Global.getSalesSmmryItmID("6Total Payments Received", -1, srcDocID, srcDocType); if (smmryID <= 0) { Global.createSmmryItm("6Total Payments Received", smmryNm, pymntsAmnt, -1, srcDocType, srcDocID, true); } else { Global.updateSmmryItm(smmryID, "6Total Payments Received", pymntsAmnt, true, smmryNm); } } int codeCntr = 0; //Tax Codes double txAmnts = 0; double dscntAmnts = 0; double extrChrgAmnts = 0; string txSmmryNm = ""; string dscntSmmryNm = ""; string chrgSmmryNm = ""; for (int i = 0; i < dtst.Tables[0].Rows.Count; i++) { int txID = int.Parse(dtst.Tables[0].Rows[i][9].ToString()); int dscntID = int.Parse(dtst.Tables[0].Rows[i][10].ToString()); int chrgID = int.Parse(dtst.Tables[0].Rows[i][11].ToString()); double unitAmnt = double.Parse(dtst.Tables[0].Rows[i][3].ToString()); double qnty = double.Parse(dtst.Tables[0].Rows[i][2].ToString()); string tmp = ""; if (txID > 0) { txAmnts += Global.getSalesDocCodesAmnt(txID, unitAmnt, qnty); tmp = Global.mnFrm.cmCde.getGnrlRecNm( "scm.scm_tax_codes", "code_id", "code_name", txID); if (!txSmmryNm.Contains(tmp)) { txSmmryNm += tmp + " + "; } codeCntr++; } if (dscntID > 0) { dscntAmnts += Global.getSalesDocCodesAmnt(dscntID, unitAmnt, qnty); tmp = Global.mnFrm.cmCde.getGnrlRecNm( "scm.scm_tax_codes", "code_id", "code_name", dscntID); if (!dscntSmmryNm.Contains(tmp)) { dscntSmmryNm += tmp + " + "; } codeCntr++; } if (chrgID > 0) { extrChrgAmnts += Global.getSalesDocCodesAmnt(chrgID, unitAmnt, qnty); tmp = Global.mnFrm.cmCde.getGnrlRecNm( "scm.scm_tax_codes", "code_id", "code_name", chrgID); if (!chrgSmmryNm.Contains(tmp)) { chrgSmmryNm += tmp + " + "; } codeCntr++; } } char[] trm = { '+' }; txSmmryNm = txSmmryNm.Trim().Trim(trm).Trim(); dscntSmmryNm = dscntSmmryNm.Trim().Trim(trm).Trim(); chrgSmmryNm = chrgSmmryNm.Trim().Trim(trm).Trim(); smmryID = Global.getSalesSmmryItmID("2Tax", -1, srcDocID, srcDocType); if (smmryID <= 0 && txAmnts > 0) { Global.createSmmryItm("2Tax", txSmmryNm, txAmnts, -1, srcDocType, srcDocID, true); } else if (txAmnts > 0) { Global.updateSmmryItm(smmryID, "2Tax", txAmnts, true, txSmmryNm); } else if (txAmnts <= 0) { Global.deleteSalesSmmryItm(srcDocID, srcDocType, "2Tax"); } smmryID = Global.getSalesSmmryItmID("3Discount", -1, srcDocID, srcDocType); if (smmryID <= 0 && dscntAmnts > 0) { Global.createSmmryItm("3Discount", dscntSmmryNm, dscntAmnts, -1, srcDocType, srcDocID, true); } else if (dscntAmnts > 0) { Global.updateSmmryItm(smmryID, "3Discount", dscntAmnts, true, dscntSmmryNm); } else if (dscntAmnts <= 0) { Global.deleteSalesSmmryItm(srcDocID, srcDocType, "3Discount"); } smmryID = Global.getSalesSmmryItmID("4Extra Charge", -1, srcDocID, srcDocType); if (smmryID <= 0 && extrChrgAmnts > 0) { Global.createSmmryItm("4Extra Charge", chrgSmmryNm, extrChrgAmnts, -1, srcDocType, srcDocID, true); } else if (extrChrgAmnts > 0) { Global.updateSmmryItm(smmryID, "4Extra Charge", extrChrgAmnts, true, chrgSmmryNm); } else if (extrChrgAmnts <= 0) { Global.deleteSalesSmmryItm(srcDocID, srcDocType, "4Extra Charge"); } //Initial Amount if (txAmnts <= 0 && dscntAmnts <= 0 && extrChrgAmnts <= 0) { Global.deleteSalesSmmryItm(srcDocID, srcDocType, "1Initial Amount"); } else if (codeCntr > 0) { smmryNm = "Initial Amount"; smmryID = Global.getSalesSmmryItmID("1Initial Amount", -1, srcDocID, srcDocType); double initAmnt = Global.getSalesDocBscAmnt(srcDocID, srcDocType); if (smmryID <= 0) { Global.createSmmryItm("1Initial Amount", smmryNm, initAmnt, -1, srcDocType, srcDocID, true); } else { Global.updateSmmryItm(smmryID, "1Initial Amount", initAmnt, true, smmryNm); } } // Grand Total grndAmnt = grndAmnt + extrChrgAmnts - dscntAmnts; smmryNm = "Grand Total"; smmryID = Global.getSalesSmmryItmID("5Grand Total", -1, srcDocID, srcDocType); if (smmryID <= 0) { Global.createSmmryItm("5Grand Total", smmryNm, grndAmnt, -1, srcDocType, srcDocID, true); } else { Global.updateSmmryItm(smmryID, "5Grand Total", grndAmnt, true, smmryNm); } //Total Payments if (srcDocType == "Sales Invoice") { //Change Given/Outstanding Balance blsAmnt = grndAmnt - pymntsAmnt; if (blsAmnt < 0) { smmryNm = "Change Given to Customer"; } else { smmryNm = "Outstanding Balance"; } smmryID = Global.getSalesSmmryItmID("7Change/Balance", -1, srcDocID, srcDocType); if (smmryID <= 0) { Global.createSmmryItm("7Change/Balance", smmryNm, blsAmnt, -1, srcDocType, srcDocID, true); } else { Global.updateSmmryItm(smmryID, "7Change/Balance", blsAmnt, true, smmryNm); } } else if (srcDocType == "Sales Return" && strSrcDocType == "Sales Invoice") { //Change Given/Outstanding Balance blsAmnt = grndAmnt - pymntsAmnt; if (blsAmnt < 0) { smmryNm = "Change Received from Customer"; } else { smmryNm = "Outstanding Balance"; } smmryID = Global.getSalesSmmryItmID("7Change/Balance", -1, srcDocID, srcDocType); if (smmryID <= 0) { Global.createSmmryItm("7Change/Balance", smmryNm, blsAmnt, -1, srcDocType, srcDocID, true); } else { Global.updateSmmryItm(smmryID, "7Change/Balance", blsAmnt, true, smmryNm); } } } private bool isPayTrnsValid(int accntID, string incrsDcrs, double amnt, string date1) { double netamnt = 0; netamnt = Global.mnFrm.cmCde.dbtOrCrdtAccntMultiplier(accntID, incrsDcrs) * amnt; if (!Global.mnFrm.cmCde.isTransPrmttd( accntID, date1, netamnt)) { return false; } return true; } public bool sendToGLInterfaceMnl(int accntID, string incrsDcrs, double amount, string trns_date, string trns_desc, int crncy_id, string dateStr, string srcDocTyp, long srcDocID, long srcDocLnID) { try { double netamnt = 0; netamnt = Global.mnFrm.cmCde.dbtOrCrdtAccntMultiplier( accntID, incrsDcrs) * amount; long py_dbt_ln = Global.getIntFcTrnsDbtLn(srcDocLnID, srcDocTyp, amount, accntID, trns_desc); long py_crdt_ln = Global.getIntFcTrnsCrdtLn(srcDocLnID, srcDocTyp, amount, accntID, trns_desc); if (Global.mnFrm.cmCde.dbtOrCrdtAccnt(accntID, incrsDcrs) == "Debit") { if (py_dbt_ln <= 0) { Global.createPymntGLIntFcLn(accntID, trns_desc, amount, trns_date, crncy_id, 0, netamnt, srcDocTyp, srcDocID, srcDocLnID, dateStr); } } else { if (py_crdt_ln <= 0) { Global.createPymntGLIntFcLn(accntID, trns_desc, 0, trns_date, crncy_id, amount, netamnt, srcDocTyp, srcDocID, srcDocLnID, dateStr); } } return true; } catch (Exception ex) { Global.mnFrm.cmCde.showMsg("Error Sending Payment to GL Interface" + " " + ex.Message, 0); return false; } } private void revrsMenuItem_Click(object sender, EventArgs e) { this.rvrsPymntButton_Click(this.rvrsPymntButton, e); } private void exptExSmryMenuItem_Click(object sender, EventArgs e) { Global.mnFrm.cmCde.exprtToExcel(this.trnsSearchListView); } private void rfrshSmryMenuItem_Click(object sender, EventArgs e) { this.goTrnsButton_Click(this.goTrnsButton, e); } private void vwSQLSmryMenuItem_Click(object sender, EventArgs e) { this.vwSQLTrnsButton_Click(this.vwSQLTrnsButton, e); } private void rcHstrySmryMenuItem_Click(object sender, EventArgs e) { this.recHstryTrnsButton_Click(this.recHstryTrnsButton, e); } private void OKButton_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; this.Close(); } } }
rhomicom-systems-tech-gh/Rhomicom-ERP-Desktop
InventoryManagment/InventoryManagment/Forms/pymntsRcvdForm.cs
C#
gpl-3.0
27,466
#!/usr/bin/python # # Problem: Endless Knight # Language: Python # Author: KirarinSnow # Usage: python thisfile.py <input.in >output.out # Comments: OK for large, but may time out on small. from itertools import * MOD = 10007 # Precompute factorial table mod MOD fact = [1] * MOD for i in xrange(1, MOD): fact[i] = (fact[i-1] * i) # n choose k -- using Lucas's theorem def choose(n, k): if k > n: return 0 elif n < MOD: return (fact[n]/fact[n-k]/fact[k])%MOD else: prod = 1 while n > 0: prod *= choose(n%MOD, k%MOD) prod %= MOD n /= MOD k /= MOD return prod def compute(): h, w, r = map(int, raw_input().split()) rocks = [map(int, raw_input().split()) for i in range(r)] if (h+w-2)%3 != 0: return 0 # normalize rock coordinates h, w = h-1-(h+w-2)/3, w-1-(h+w-2)/3 for i in range(r): row, col = rocks[i] if (row+col-2)%3 != 0: rocks[i] = None else: rocks[i] = [row-1-(row+col-2)/3, col-1-(row+col-2)/3] if rocks[i][0] < 0 or rocks[i][0] > h: rocks[i] = None elif rocks[i][1] < 0 or rocks[i][1] > w: rocks[i] = None total = 0 for num in range(r+1): for perm in permutations(range(r), num): # verify increasing property of permutation inc = True for i in range(num): if rocks[perm[i]] == None: inc = False break if i > 0: if rocks[perm[i]][0] < rocks[perm[i-1]][0]: inc = False break if rocks[perm[i]][1] < rocks[perm[i-1]][1]: inc = False break if inc: points = [[0,0]] + [rocks[j] for j in perm] + [[h,w]] # number of paths going through all points prod = 1 for j in range(1, len(points)): dh = points[j][0] - points[j-1][0] dw = points[j][1] - points[j-1][1] prod *= choose(dh+dw, dw) prod %= MOD # inclusion-exclusion total += (-1)**num * prod total %= MOD return total for i in range(input()): print "Case #%d: %d" % (i+1, compute())
KirarinSnow/Google-Code-Jam
Round 3 2008/D1.py
Python
gpl-3.0
2,492
package com.mec.servlet; import java.io.IOException; import java.io.PrintWriter; import java.util.Random; import javax.servlet.ServletException; import javax.servlet.annotation.WebInitParam; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author MEC */ @WebServlet(name = "ES6PromiseServlet", urlPatterns = {"/ES6Promise"}) //@WebInitParam(name = "url", value = "ES6Promise") public class ES6PromiseServlet extends HttpServlet { private static final String INIT_PARA_URL = "url"; private static final String REQUEST_TYPE = "type"; private static final String TYPE_VALUE = "url"; private static final String SERVLET_URL = "ES6Promise"; /** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String requestType = request.getParameter(REQUEST_TYPE); if(TYPE_VALUE.equalsIgnoreCase(requestType)){ //out.print(getInitParameter(INIT_PARA_URL)); out.print(SERVLET_URL); }else{ out.print(rand.nextInt()); } } finally { out.close(); } } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** * Handles the HTTP <code>GET</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP <code>POST</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "ES6 Promise"; }// </editor-fold> private static final Random rand = new Random(System.currentTimeMillis()); }
mectest1/HelloEE
HelloJS/src/com/mec/servlet/ES6PromiseServlet.java
Java
gpl-3.0
3,026
package de.TheJulianJES.UtilsPlus.Blocks; import net.minecraft.block.Block; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import de.TheJulianJES.UtilsPlus.lib.StringNames; public class ItemBlockDeco extends ItemBlock { public ItemBlockDeco(Block block) { super(block); this.setHasSubtypes(true); } @Override public int getMetadata(int meta) { return meta; } @Override public String getUnlocalizedName(ItemStack itemStack) { int metaData = itemStack.getItemDamage(); return String.format("tile.%s%s", StringNames.MODID.toLowerCase() + ":", "deco." + metaData); } }
TheJulianJES/UtilsPlus
src/main/java/de/TheJulianJES/UtilsPlus/Blocks/ItemBlockDeco.java
Java
gpl-3.0
615
/****************************************************************************** * * MantaFlow fluid solver framework * Copyright 2011 Tobias Pfaff, Nils Thuerey * * This program is free software, distributed under the terms of the * GNU General Public License (GPL) * http://www.gnu.org/licenses * * Python argument wrappers and conversion tools * ******************************************************************************/ #include "pythonInclude.h" #include <sstream> #include <algorithm> #include "vectorbase.h" #include "manta.h" using namespace std; //****************************************************************************** // Explicit definition and instantiation of python object converters namespace Manta { extern PyTypeObject PbVec3Type; extern PyTypeObject PbVec4Type; struct PbVec3 { PyObject_HEAD float data[3]; }; struct PbVec4 { PyObject_HEAD float data[4]; }; PyObject* getPyNone() { Py_INCREF(Py_None); return Py_None; } PyObject* incref(PyObject* obj) { Py_INCREF(obj); return obj; } /*template<> PyObject* toPy<PyObject*>(PyObject* obj) { return obj; }*/ template<> PyObject* toPy<int>( const int& v) { return PyLong_FromLong(v); } /*template<> PyObject* toPy<char*>(const (char*) & val) { return PyUnicode_DecodeLatin1(val,strlen(val),"replace"); }*/ template<> PyObject* toPy<string>( const string& val) { return PyUnicode_DecodeLatin1(val.c_str(),val.length(),"replace"); } template<> PyObject* toPy<float>( const float& v) { return PyFloat_FromDouble(v); } template<> PyObject* toPy<double>( const double& v) { return PyFloat_FromDouble(v); } template<> PyObject* toPy<bool>( const bool& v) { return PyBool_FromLong(v); } template<> PyObject* toPy<Vec3i>(const Vec3i& v) { float x=(float)v.x, y=(float)v.y, z=(float)v.z; return PyObject_CallFunction((PyObject*)&PbVec3Type, (char*)"fff", x, y, z); } template<> PyObject* toPy<Vec3>(const Vec3& v) { float x=(float)v.x, y=(float)v.y, z=(float)v.z; return PyObject_CallFunction((PyObject*)&PbVec3Type, (char*)"fff", x, y, z); } template<> PyObject* toPy<Vec4i>(const Vec4i& v) { float x=(float)v.x, y=(float)v.y, z=(float)v.z; return PyObject_CallFunction((PyObject*)&PbVec4Type, (char*)"ffff", x, y, z); } template<> PyObject* toPy<Vec4>(const Vec4& v) { float x=(float)v.x, y=(float)v.y, z=(float)v.z; return PyObject_CallFunction((PyObject*)&PbVec4Type, (char*)"ffff", x, y, z); } template<> PyObject* toPy<PbClass*>(const PbClass_Ptr& obj) { return obj->getPyObject(); } template<> float fromPy<float>(PyObject* obj) { #if PY_MAJOR_VERSION <= 2 if (PyInt_Check(obj)) return PyInt_AsLong(obj); #endif if (PyFloat_Check(obj)) return PyFloat_AsDouble(obj); if (PyLong_Check(obj)) return PyLong_AsDouble(obj); errMsg("argument is not a float"); } template<> double fromPy<double>(PyObject* obj) { #if PY_MAJOR_VERSION <= 2 if (PyInt_Check(obj)) return PyInt_AsLong(obj); #endif if (PyFloat_Check(obj)) return PyFloat_AsDouble(obj); if (PyLong_Check(obj)) return PyLong_AsDouble(obj); errMsg("argument is not a double"); } template<> PyObject* fromPy<PyObject*>(PyObject *obj) { return obj; } template<> int fromPy<int>(PyObject *obj) { #if PY_MAJOR_VERSION <= 2 if (PyInt_Check(obj)) return PyInt_AsLong(obj); #endif if (PyLong_Check(obj)) return PyLong_AsDouble(obj); if (PyFloat_Check(obj)) { double a = PyFloat_AsDouble(obj); if (fabs(a-floor(a+0.5)) > 1e-5) errMsg("argument is not an int"); return (int) (a+0.5); } errMsg("argument is not an int"); } template<> string fromPy<string>(PyObject *obj) { if (PyUnicode_Check(obj)) return PyBytes_AsString(PyUnicode_AsLatin1String(obj)); #if PY_MAJOR_VERSION <= 2 else if (PyString_Check(obj)) return PyString_AsString(obj); #endif else errMsg("argument is not a string"); } template<> const char* fromPy<const char*>(PyObject *obj) { if (PyUnicode_Check(obj)) return PyBytes_AsString(PyUnicode_AsLatin1String(obj)); #if PY_MAJOR_VERSION <= 2 else if (PyString_Check(obj)) return PyString_AsString(obj); #endif else errMsg("argument is not a string"); } template<> bool fromPy<bool>(PyObject *obj) { if (!PyBool_Check(obj)) errMsg("argument is not a boolean"); return PyLong_AsLong(obj) != 0; } template<> Vec3 fromPy<Vec3>(PyObject* obj) { if (PyObject_IsInstance(obj, (PyObject*)&PbVec3Type)) { return Vec3(((PbVec3*)obj)->data); } else if (PyTuple_Check(obj) && PyTuple_Size(obj) == 3) { return Vec3(fromPy<Real>(PyTuple_GetItem(obj,0)), fromPy<Real>(PyTuple_GetItem(obj,1)), fromPy<Real>(PyTuple_GetItem(obj,2))); } errMsg("argument is not a Vec3"); } template<> Vec3i fromPy<Vec3i>(PyObject* obj) { if (PyObject_IsInstance(obj, (PyObject*)&PbVec3Type)) { return toVec3iChecked(((PbVec3*)obj)->data); } else if (PyTuple_Check(obj) && PyTuple_Size(obj) == 3) { return Vec3i(fromPy<int>(PyTuple_GetItem(obj,0)), fromPy<int>(PyTuple_GetItem(obj,1)), fromPy<int>(PyTuple_GetItem(obj,2))); } errMsg("argument is not a Vec3i"); } template<> Vec4 fromPy<Vec4>(PyObject* obj) { if (PyObject_IsInstance(obj, (PyObject*)&PbVec4Type)) { return Vec4(((PbVec4*)obj)->data); } else if (PyTuple_Check(obj) && PyTuple_Size(obj) == 4) { return Vec4(fromPy<Real>(PyTuple_GetItem(obj,0)), fromPy<Real>(PyTuple_GetItem(obj,1)), fromPy<Real>(PyTuple_GetItem(obj,2)), fromPy<Real>(PyTuple_GetItem(obj,3))); } errMsg("argument is not a Vec4"); } template<> Vec4i fromPy<Vec4i>(PyObject* obj) { if (PyObject_IsInstance(obj, (PyObject*)&PbVec4Type)) { return toVec4i(((PbVec4*)obj)->data); } else if (PyTuple_Check(obj) && PyTuple_Size(obj) == 4) { return Vec4i(fromPy<int>(PyTuple_GetItem(obj,0)), fromPy<int>(PyTuple_GetItem(obj,1)), fromPy<int>(PyTuple_GetItem(obj,2)), fromPy<int>(PyTuple_GetItem(obj,3))); } errMsg("argument is not a Vec4i"); } template<> PbType fromPy<PbType>(PyObject* obj) { PbType pb = {""}; if (!PyType_Check(obj)) return pb; const char* tname = ((PyTypeObject*)obj)->tp_name; pb.S = tname; return pb; } template<> PbTypeVec fromPy<PbTypeVec>(PyObject* obj) { PbTypeVec vec; if (PyType_Check(obj)) { vec.T.push_back(fromPy<PbType>(obj)); } else if (PyTuple_Check(obj)) { int sz = PyTuple_Size(obj); for (int i=0; i< sz; i++) vec.T.push_back(fromPy<PbType>(PyTuple_GetItem(obj,i))); } else errMsg("argument is not a type tuple"); return vec; } template<class T> T* tmpAlloc(PyObject* obj,std::vector<void*>* tmp) { if (!tmp) throw Error("dynamic de-ref not supported for this type"); void* ptr = malloc(sizeof(T)); tmp->push_back(ptr); *((T*)ptr) = fromPy<T>(obj); return (T*)ptr; } template<> float* fromPyPtr<float>(PyObject* obj, std::vector<void*>* tmp) { return tmpAlloc<float>(obj,tmp); } template<> double* fromPyPtr<double>(PyObject* obj, std::vector<void*>* tmp) { return tmpAlloc<double>(obj,tmp); } template<> int* fromPyPtr<int>(PyObject* obj, std::vector<void*>* tmp) { return tmpAlloc<int>(obj,tmp); } template<> std::string* fromPyPtr<std::string>(PyObject* obj, std::vector<void*>* tmp) { return tmpAlloc<std::string>(obj,tmp); } template<> bool* fromPyPtr<bool>(PyObject* obj, std::vector<void*>* tmp) { return tmpAlloc<bool>(obj,tmp); } template<> Vec3* fromPyPtr<Vec3>(PyObject* obj, std::vector<void*>* tmp) { return tmpAlloc<Vec3>(obj,tmp); } template<> Vec3i* fromPyPtr<Vec3i>(PyObject* obj, std::vector<void*>* tmp) { return tmpAlloc<Vec3i>(obj,tmp); } template<> Vec4* fromPyPtr<Vec4>(PyObject* obj, std::vector<void*>* tmp) { return tmpAlloc<Vec4>(obj,tmp); } template<> Vec4i* fromPyPtr<Vec4i>(PyObject* obj, std::vector<void*>* tmp) { return tmpAlloc<Vec4i>(obj,tmp); } template<> bool isPy<float>(PyObject* obj) { #if PY_MAJOR_VERSION <= 2 if (PyInt_Check(obj)) return true; #endif return PyFloat_Check(obj) || PyLong_Check(obj); } template<> bool isPy<double>(PyObject* obj) { #if PY_MAJOR_VERSION <= 2 if (PyInt_Check(obj)) return true; #endif return PyFloat_Check(obj) || PyLong_Check(obj); } template<> bool isPy<PyObject*>(PyObject *obj) { return true; } template<> bool isPy<int>(PyObject *obj) { #if PY_MAJOR_VERSION <= 2 if (PyInt_Check(obj)) return true; #endif if (PyLong_Check(obj)) return true; if (PyFloat_Check(obj)) { double a = PyFloat_AsDouble(obj); return fabs(a-floor(a+0.5)) < 1e-5; } return false; } template<> bool isPy<string>(PyObject *obj) { if (PyUnicode_Check(obj)) return true; #if PY_MAJOR_VERSION <= 2 if (PyString_Check(obj)) return true; #endif return false; } template<> bool isPy<const char*>(PyObject *obj) { if (PyUnicode_Check(obj)) return true; #if PY_MAJOR_VERSION <= 2 if (PyString_Check(obj)) return true; #endif return false; } template<> bool isPy<bool>(PyObject *obj) { return PyBool_Check(obj); } template<> bool isPy<Vec3>(PyObject* obj) { if (PyObject_IsInstance(obj, (PyObject*)&PbVec3Type)) return true; if (PyTuple_Check(obj) && PyTuple_Size(obj) == 3) { return isPy<Real>(PyTuple_GetItem(obj,0)) && isPy<Real>(PyTuple_GetItem(obj,1)) && isPy<Real>(PyTuple_GetItem(obj,2)); } return false; } template<> bool isPy<Vec3i>(PyObject* obj) { if (PyObject_IsInstance(obj, (PyObject*)&PbVec3Type)) return true; if (PyTuple_Check(obj) && PyTuple_Size(obj) == 3) { return isPy<int>(PyTuple_GetItem(obj,0)) && isPy<int>(PyTuple_GetItem(obj,1)) && isPy<int>(PyTuple_GetItem(obj,2)); } return false; } template<> bool isPy<Vec4>(PyObject* obj) { if (PyObject_IsInstance(obj, (PyObject*)&PbVec4Type)) return true; if (PyTuple_Check(obj) && PyTuple_Size(obj) == 4) { return isPy<Real>(PyTuple_GetItem(obj,0)) && isPy<Real>(PyTuple_GetItem(obj,1)) && isPy<Real>(PyTuple_GetItem(obj,2)) && isPy<Real>(PyTuple_GetItem(obj,3)); } return false; } template<> bool isPy<Vec4i>(PyObject* obj) { if (PyObject_IsInstance(obj, (PyObject*)&PbVec4Type)) return true; if (PyTuple_Check(obj) && PyTuple_Size(obj) == 4) { return isPy<int>(PyTuple_GetItem(obj,0)) && isPy<int>(PyTuple_GetItem(obj,1)) && isPy<int>(PyTuple_GetItem(obj,2)) && isPy<int>(PyTuple_GetItem(obj,3)); } return false; } template<> bool isPy<PbType>(PyObject* obj) { return PyType_Check(obj); } //****************************************************************************** // PbArgs class defs PbArgs PbArgs::EMPTY(NULL,NULL); PbArgs::PbArgs(PyObject* linarg, PyObject* dict) : mLinArgs(0), mKwds(0) { setup(linarg, dict); } PbArgs::~PbArgs() { for(int i=0; i<(int)mTmpStorage.size(); i++) free(mTmpStorage[i]); mTmpStorage.clear(); } void PbArgs::copy(PbArgs& a) { mKwds = a.mKwds; mData = a.mData; mLinData = a.mLinData; mLinArgs = a.mLinArgs; } void PbArgs::clear() { mLinArgs = 0; mKwds = 0; mData.clear(); mLinData.clear(); } PbArgs& PbArgs::operator=(const PbArgs& a) { // mLinArgs = 0; // mKwds = 0; return *this; } void PbArgs::setup(PyObject* linarg, PyObject* dict) { if (dict) { PyObject *key, *value; Py_ssize_t pos = 0; while (PyDict_Next(dict, &pos, &key, &value)) { DataElement el; el.obj = value; el.visited = false; mData[fromPy<string>(key)] = el; } mKwds = dict; } if (linarg) { size_t len = PyTuple_Size(linarg); for (size_t i=0; i<len; i++) { DataElement el; el.obj = PyTuple_GetItem(linarg, i); el.visited = false; mLinData.push_back(el); } mLinArgs = linarg; } } void PbArgs::addLinArg(PyObject* obj) { DataElement el = { obj, false }; mLinData.push_back(el); } void PbArgs::check() { if (has("nocheck")) return; for(map<string, DataElement>::iterator it = mData.begin(); it != mData.end(); it++) { if (!it->second.visited) errMsg("Argument '" + it->first + "' unknown"); } for(size_t i=0; i<mLinData.size(); i++) { if (!mLinData[i].visited) { stringstream s; s << "Function does not read argument number #" << i; errMsg(s.str()); } } } FluidSolver* PbArgs::obtainParent() { FluidSolver* solver = getPtrOpt<FluidSolver>("solver",-1,NULL); if (solver != 0) return solver; for(map<string, DataElement>::iterator it = mData.begin(); it != mData.end(); it++) { PbClass* obj = Pb::objFromPy(it->second.obj); if (obj) { if (solver == NULL) solver = obj->getParent(); } } for(vector<DataElement>::iterator it = mLinData.begin(); it != mLinData.end(); it++) { PbClass* obj = Pb::objFromPy(it->obj); if (obj) { if (solver == NULL) solver = obj->getParent(); } } return solver; } void PbArgs::visit(int number, const string& key) { if (number >= 0 && number < (int)mLinData.size()) mLinData[number].visited = true; map<string, DataElement>::iterator lu = mData.find(key); if (lu != mData.end()) lu->second.visited = true; } PyObject* PbArgs::getItem(const std::string& key, bool strict, ArgLocker* lk) { map<string, DataElement>::iterator lu = mData.find(key); if (lu == mData.end()) { if (strict) errMsg ("Argument '" + key + "' is not defined."); return NULL; } PbClass* pbo = Pb::objFromPy(lu->second.obj); // try to lock if (pbo && lk) lk->add(pbo); return lu->second.obj; } PyObject* PbArgs::getItem(size_t number, bool strict, ArgLocker* lk) { if (number >= mLinData.size()) { if (!strict) return NULL; stringstream s; s << "Argument number #" << number << " not specified."; errMsg(s.str()); } PbClass* pbo = Pb::objFromPy(mLinData[number].obj); // try to lock if (pbo && lk) lk->add(pbo); return mLinData[number].obj; } //****************************************************************************** // ArgLocker class defs void ArgLocker::add(PbClass* p) { if (find(locks.begin(), locks.end(), p) == locks.end()) { locks.push_back(p); p->lock(); } } ArgLocker::~ArgLocker() { for (size_t i=0; i<locks.size(); i++) locks[i]->unlock(); locks.clear(); } } // namespace
CoderDuan/mantaflow
source/pwrapper/pconvert.cpp
C++
gpl-3.0
13,839
package com.greenaddress.greenbits.spv; import org.bitcoinj.core.BloomFilter; class PeerFilterProvider implements org.bitcoinj.core.PeerFilterProvider { private final SPV mSPV; public PeerFilterProvider(final SPV spv) { mSPV = spv; } @Override public long getEarliestKeyCreationTime() { final Integer n = mSPV.getService().getLoginData().get("earliest_key_creation_time"); return n.longValue(); } @Override public int getBloomFilterElementCount() { return mSPV.getBloomFilterElementCount(); } @Override public BloomFilter getBloomFilter(final int size, final double falsePositiveRate, final long nTweak) { return mSPV.getBloomFilter(size, falsePositiveRate, nTweak); } @Override public boolean isRequiringUpdateAllBloomFilter() { return false; } public void beginBloomFilterCalculation(){ //TODO: ?? } public void endBloomFilterCalculation(){ //TODO: ?? } }
greenaddress/GreenBits
app/src/main/java/com/greenaddress/greenbits/spv/PeerFilterProvider.java
Java
gpl-3.0
994
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using SandbarWorkbench.ModelRuns; namespace SandbarWorkbench { public partial class frmSynchronize : Form { DBHelpers.SyncHelpers syncEngine; int nTaskPercentage = 0; public frmSynchronize() { InitializeComponent(); } private int VariableHeight { get { return grpProgress.Height - (grpProgress.Top - chkResults.Bottom); } } private void frmSynchronize_Load(object sender, EventArgs e) { tt.SetToolTip(chkLookup, "Check this box to synchronize lookup tables between the master and local database."); tt.SetToolTip(chkResults, "Check this box to synchronize sandbar analysis results to and from the master database."); tt.SetToolTip(pgrOverall, "The overall progress for the entire synchronize process."); tt.SetToolTip(pgrTask, "The progress of the individual synchronization task being performed."); // Hide the progress group box and resize the form. Note the border is fixed until user clicks OK. grpProgress.Visible = false; this.FormBorderStyle = FormBorderStyle.FixedDialog; this.Height = this.Height - VariableHeight; this.MinimumSize = new Size(this.Width, this.Height); } private void cmdOK_Click(object sender, EventArgs e) { if (!(chkLookup.Checked || chkResults.Checked)) { MessageBox.Show("You must choose one or both of the data types to synchronize.", SandbarWorkbench.Properties.Resources.ApplicationNameLong, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.None; return; } // Close all MDI children (easier than refreshing them!) ((frmMain)this.Owner).CloseMDIChildren(); if (!grpProgress.Visible) { grpProgress.Visible = true; this.Height += VariableHeight; this.MinimumSize = new Size(this.Width, this.Height); this.FormBorderStyle = FormBorderStyle.Sizable; grpProgress.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom; } try { txtProgress.Text = string.Empty; cmdOK.Enabled = false; syncEngine = new DBHelpers.SyncHelpers("SandbarData", DBCon.ConnectionStringMaster, DBCon.ConnectionStringLocal); syncEngine.OnProgressUpdate += syncEngine_OnProgressUpdate; syncEngine.LookupTables = chkLookup.Checked || chkResults.Checked; syncEngine.ModelRunTables = chkResults.Checked; bgWorker.RunWorkerAsync(); foreach (Form frm in this.MdiChildren) { if (frm is Sandbars.frmSandbars) { ((Sandbars.frmSandbars)frm).LoadData(); } } } catch (Exception ex) { ExceptionHandling.NARException.HandleException(ex); } } #region Background worker events /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks>http://stackoverflow.com/questions/14871238/report-progress-backgroundworker-from-different-class-c-sharp</remarks> private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { try { syncEngine.Synchronize(); } catch (Exception ex) { ExceptionHandling.NARException.HandleException(ex); } } private void syncEngine_OnProgressUpdate(int nOverall, int nTask) { nTaskPercentage = nTask; bgWorker.ReportProgress(nOverall); } private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { for (int i = txtProgress.Lines.Count<string>(); i < syncEngine.Messages.Count<string>(); i++) txtProgress.AppendText(syncEngine.Messages[i] + "\r\n"); if (e.ProgressPercentage != -1) pgrOverall.Value = e.ProgressPercentage; if (nTaskPercentage != -1) pgrTask.Value = nTaskPercentage; } private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { cmdOK.Enabled = true; cmdCancel.Text = "Close"; } #endregion private void cmdHelp_Click(object sender, EventArgs e) { Helpers.OnlineHelp.FormHelp(this.Name); } private void frmSynchronize_HelpRequested(object sender, HelpEventArgs hlpevent) { Helpers.OnlineHelp.FormHelp(this.Name); } } }
NorthArrowResearch/sandbar-analysis-workbench
SandbarWorkbench/frmSynchronize.cs
C#
gpl-3.0
5,268
package statalign.base.hmm; /** * The abstract class of Hidden Markov Models. * * @author novak * */ public abstract class Hmm { /** * HMM model parameters. Implementing classes can use their own assignment and * any number of parameters. * In the case of the TKF92 model (HmmTkf92), values are: r, lambda and mu. */ public double[] params; /** * Abstract function that specifies the emission of each state in the HMM in the form * of an array A: A[s][i]=1 iff state i emits into sequence s (s=0 is the parent sequence; * for pair-HMMs s=1 is the child sequence, for 3-seq HMMs s=1 is left and s=2 is right * child). * HMM implementations must override this and return their own emission patterns. * @return array specifying emission patterns as described above */ public abstract int[][] getStateEmit(); /** * Abstract function returning an array A that helps identify the state with some * emission pattern. The emission pattern is coded as a single integer: e.g. for a 3-seq * HMM, emission into the parent sequence and right child only is coded as 101 binary, * i.e. 4+1=5. Then, A[5] gives the index of the state with the above emission pattern. * HMM implementations must override this and return an array corresponding to their own * state - emission pattern assignment. * @return array describing the emission pattern to state conversion */ public abstract int[] getEmitPatt2State(); /** * Returns the index of the start state. * * @return The index of the start state; */ public abstract int getStart(); /** * Returns the index of the end state. * * @return The index of the end state; */ public abstract int getEnd(); /** * Returns the logarithm of the stationary probability of generating * a sequence of <code>length</code> characters under the HMM. * @param length The length of the sequence whose stationary * probability is to be computed. * @return The logarithm of the stationary probability under the HMM. */ public double getLogStationaryProb(int length) { return 0.0; } }
statalign/statalign
src/statalign/base/hmm/Hmm.java
Java
gpl-3.0
2,170
//============================================================================= /*! zgematrix+=zhematrix operator */ inline zgematrix& zgematrix::operator+=(const zhematrix& mat) {CPPL_VERBOSE_REPORT; #ifdef CPPL_DEBUG if(n!=mat.n || m!=mat.n){ ERROR_REPORT; std::cerr << "These two matrises can not make a summation." << std::endl << "Your input was (" << m << "x" << n << ") += (" << mat.n << "x" << mat.n << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG for(CPPL_INT i=0; i<m; i++){ for( CPPL_INT j=0; j<n; j++){ operator()(i,j) += mat(i,j); } } return *this; } //============================================================================= /*! zgematrix-=zhematrix operator */ inline zgematrix& zgematrix::operator-=(const zhematrix& mat) {CPPL_VERBOSE_REPORT; #ifdef CPPL_DEBUG if(n!=mat.n || m!=mat.n){ ERROR_REPORT; std::cerr << "These two matrises can not make a sutraction." << std::endl << "Your input was (" << m << "x" << n << ") -= (" << mat.n << "x" << mat.n << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG for(CPPL_INT i=0; i<m; i++){ for(CPPL_INT j=0; j<n; j++){ operator()(i,j) -= mat(i,j); } } return *this; } //============================================================================= /*! zgematrix*=zhematrix operator */ inline zgematrix& zgematrix::operator*=(const zhematrix& mat) {CPPL_VERBOSE_REPORT; #ifdef CPPL_DEBUG if(n!=mat.n){ ERROR_REPORT; std::cerr << "These two matrises can not make a product." << std::endl << "Your input was (" << m << "x" << n << ") *= (" << mat.n << "x" << mat.n << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat( m, mat.n ); char side ='R'; char uplo ='l'; comple alpha =comple(1.,0.); comple beta =comple(0.,0.); zhemm_( &side, &uplo, &mat.n, &n, &alpha, mat.array, &mat.n, array, &m, &beta, newmat.array, &newmat.m ); swap(*this,newmat); return *this; } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// //============================================================================= /*! zgematrix+zhematrix operator */ inline _zgematrix operator+(const zgematrix& matA, const zhematrix& matB) {CPPL_VERBOSE_REPORT; #ifdef CPPL_DEBUG if(matA.n!=matB.n || matA.m!=matB.n){ ERROR_REPORT; std::cerr << "These two matrises can not make a summation." << std::endl << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.n << "x" << matB.n << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat =matA; for(CPPL_INT i=0; i<matA.m; i++){ for(CPPL_INT j=0; j<matA.n; j++){ newmat(i,j) += matB(i,j); } } return _(newmat); } //============================================================================= /*! zgematrix-zhematrix operator */ inline _zgematrix operator-(const zgematrix& matA, const zhematrix& matB) {CPPL_VERBOSE_REPORT; #ifdef CPPL_DEBUG if(matA.n!=matB.n || matA.m!=matB.n){ ERROR_REPORT; std::cerr << "These two matrises can not make a subtraction." << std::endl << "Your input was (" << matA.m << "x" << matA.n << ") - (" << matB.n << "x" << matB.n << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat =matA; for(CPPL_INT i=0; i<matA.m; i++){ for(CPPL_INT j=0; j<matA.n; j++){ newmat(i,j) -= matB(i,j); } } return _(newmat); } //============================================================================= /*! zgematrix*zhematrix operator */ inline _zgematrix operator*(const zgematrix& matA, const zhematrix& matB) {CPPL_VERBOSE_REPORT; #ifdef CPPL_DEBUG if(matA.n!=matB.n){ ERROR_REPORT; std::cerr << "These two matrises can not make a product." << std::endl << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.n << "x" << matB.n << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat( matA.m, matA.n ); char side ='R'; char uplo ='l'; comple alpha =comple(1.,0.); comple beta =comple(0.,0.); zhemm_( &side, &uplo, &newmat.m, &newmat.n, &alpha, matB.array, &matB.n, matA.array, &matA.m, &beta, newmat.array, &newmat.m ); return _(newmat); }
j-otsuki/SpM
thirdparty/cpplapack/include/zgematrix-/zgematrix-zhematrix.hpp
C++
gpl-3.0
4,454
package org.pepsoft.worldpainter.selection; import org.pepsoft.worldpainter.layers.Layer; import org.pepsoft.worldpainter.layers.renderers.LayerRenderer; import org.pepsoft.worldpainter.layers.renderers.TransparentColourRenderer; /** * A block-level layer which indicates that a block belongs to the selection. * * <p>Created by Pepijn Schmitz on 03-11-16. */ public class SelectionBlock extends Layer { public SelectionBlock() { super(SelectionBlock.class.getName(), "SelectionBlock", "Selected area with block resolution", DataSize.BIT, 85); } @Override public LayerRenderer getRenderer() { return RENDERER; } public static final SelectionBlock INSTANCE = new SelectionBlock(); private static final LayerRenderer RENDERER = new TransparentColourRenderer(0xffff00); }
Captain-Chaos/WorldPainter
WorldPainter/WPCore/src/main/java/org/pepsoft/worldpainter/selection/SelectionBlock.java
Java
gpl-3.0
821
/** * Copyright (c) 2012 Todoroo Inc * * See the file "LICENSE" for the full license governing this code. */ package com.todoroo.astrid.data; import android.content.ContentValues; import android.net.Uri; import com.todoroo.andlib.data.AbstractModel; import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.Table; import org.tasks.BuildConfig; /** * Data Model which represents a piece of metadata associated with a task * * @author Tim Su <tim@todoroo.com> * */ public class Metadata extends AbstractModel { // --- table /** table for this model */ public static final Table TABLE = new Table("metadata", Metadata.class); /** content uri for this model */ public static final Uri CONTENT_URI = Uri.parse("content://" + BuildConfig.APPLICATION_ID + "/" + TABLE.name); // --- properties /** ID */ public static final LongProperty ID = new LongProperty( TABLE, ID_PROPERTY_NAME); /** Associated Task */ public static final LongProperty TASK = new LongProperty( TABLE, "task"); /** Metadata Key */ public static final StringProperty KEY = new StringProperty( TABLE, "key"); /** Metadata Text Value Column 1 */ public static final StringProperty VALUE1 = new StringProperty( TABLE, "value"); /** Metadata Text Value Column 2 */ public static final StringProperty VALUE2 = new StringProperty( TABLE, "value2"); /** Metadata Text Value Column 3 */ public static final StringProperty VALUE3 = new StringProperty( TABLE, "value3"); /** Metadata Text Value Column 4 */ public static final StringProperty VALUE4 = new StringProperty( TABLE, "value4"); /** Metadata Text Value Column 5 */ public static final StringProperty VALUE5 = new StringProperty( TABLE, "value5"); public static final StringProperty VALUE6 = new StringProperty( TABLE, "value6"); public static final StringProperty VALUE7 = new StringProperty( TABLE, "value7"); /** Unixtime Metadata was created */ public static final LongProperty CREATION_DATE = new LongProperty( TABLE, "created"); /** Unixtime metadata was deleted/tombstoned */ public static final LongProperty DELETION_DATE = new LongProperty( TABLE, "deleted"); /** List of all properties for this model */ public static final Property<?>[] PROPERTIES = generateProperties(Metadata.class); // --- defaults /** Default values container */ private static final ContentValues defaultValues = new ContentValues(); static { defaultValues.put(DELETION_DATE.name, 0L); } public Metadata() { super(); } public Metadata(Metadata metadata) { super(metadata); } @Override public ContentValues getDefaultValues() { return defaultValues; } @Override public long getId() { return getIdHelper(ID); } // --- parcelable helpers private static final Creator<Metadata> CREATOR = new ModelCreator<>(Metadata.class); public Long getDeletionDate() { return getValue(DELETION_DATE); } public void setDeletionDate(Long deletionDate) { setValue(DELETION_DATE, deletionDate); } public Long getTask() { return getValue(TASK); } public void setTask(Long task) { setValue(TASK, task); } public Long getCreationDate() { return getValue(CREATION_DATE); } public void setCreationDate(Long creationDate) { setValue(CREATION_DATE, creationDate); } public String getKey() { return getValue(KEY); } public void setKey(String key) { setValue(KEY, key); } }
a-v-k/astrid
src/main/java/com/todoroo/astrid/data/Metadata.java
Java
gpl-3.0
3,924
//---------------------------------------------------------------------------- // XC program; finite element analysis code // for structural analysis and design. // // Copyright (C) Luis Claudio Pérez Tato // // This program derives from OpenSees <http://opensees.berkeley.edu> // developed by the «Pacific earthquake engineering research center». // // Except for the restrictions that may arise from the copyright // of the original program (see copyright_opensees.txt) // XC is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This software is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // // You should have received a copy of the GNU General Public License // along with this program. // If not, see <http://www.gnu.org/licenses/>. //---------------------------------------------------------------------------- //=============================================================================== //# COPYRIGHT (C): Woody's license (by BJ): // ``This source code is Copyrighted in // U.S., for an indefinite period, and anybody // caught using it without our permission, will be // mighty good friends of ourn, cause we don't give // a darn. Hack it. Compile it. Debug it. Run it. // Yodel it. Enjoy it. We wrote it, that's all we // wanted to do.'' // //# PROJECT: Object Oriented Finite XC::Element Program //# PURPOSE: Finite Deformation Hyper-Elastic classes //# CLASS: //# //# VERSION: 0.6_(1803398874989) (golden section) //# LANGUAGE: C++ //# TARGET OS: all... //# DESIGN: Zhao Cheng, Boris Jeremic (jeremic@ucdavis.edu) //# PROGRAMMER(S): Zhao Cheng, Boris Jeremic //# //# //# DATE: July 2004 //# UPDATE HISTORY: //# //=============================================================================== #ifndef fdFlow_CPP #define fdFlow_CPP #include "material/nD/FiniteDeformation/fdFlow/fdFlow.h" #include <utility/matrix/nDarray/stresst.h> XC::fdFlow::fdFlow() { } double XC::fdFlow::dFodq(const XC::stresstensor &sts, const XC::FDEPState &fdepstate ) const { return 0.0; } XC::stresstensor XC::fdFlow::dFoda(const XC::stresstensor &sts, const XC::FDEPState &fdepstate ) const { XC::stresstensor Z2; return Z2; } XC::BJtensor XC::fdFlow::d2Fodsds(const XC::stresstensor &sts, const XC::FDEPState &fdepstate ) const { BJtensor Z4(4, def_dim_4, 0.0); return Z4; } XC::stresstensor XC::fdFlow::d2Fodsdq(const XC::stresstensor &sts, const XC::FDEPState &fdepstate ) const { XC::stresstensor Z2; return Z2; } XC::BJtensor XC::fdFlow::d2Fodsda(const XC::stresstensor &sts, const XC::FDEPState &fdepstate ) const { BJtensor Z4(4, def_dim_4, 0.0); return Z4; } double XC::fdFlow::d2Fodqdq(const XC::stresstensor &sts, const XC::FDEPState &fdepstate ) const { return 0.0; } XC::stresstensor XC::fdFlow::d2Fodqda(const XC::stresstensor &sts, const XC::FDEPState &fdepstate ) const { XC::stresstensor Z2; return Z2; } XC::BJtensor XC::fdFlow::d2Fodada(const XC::stresstensor &sts, const XC::FDEPState &fdepstate ) const { BJtensor Z4(4, def_dim_4, 0.0); return Z4; } std::ostream& operator<<(std::ostream &os, const XC::fdFlow &fdfl) { os << "fdFlow Parameters: " << "\n"; return os; } #endif
lcpt/xc
src/material/nD/FiniteDeformation/fdFlow/fdFlow.cpp
C++
gpl-3.0
3,813
/** * A script for handling the bootstrap switch on the resume page. */ // Import css. require("bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css"); require('bootstrap-switch'); $("[name='my-checkbox']").bootstrapSwitch(); // http://www.bootstrap-switch.org/events.html $('input[name="my-checkbox"]').on('switchChange.bootstrapSwitch', function(event, state) { var img = document.getElementById("resume-image"); var pdf_link = document.getElementById('pdf_link'); if (state) { img.src = "/Content/Resume/resume.png"; // Changes the download link. pdf_link.href = "/Content/Resume/resume.pdf"; pdf_link.download = 'MattGaikemaResume'; } else { img.src = "/Content/Resume/cv.png"; pdf_link.href = "/Content/Resume/cv.pdf"; pdf_link.download = 'MattGaikemaCV'; } });
TexAgg/website
website/Scripts/resume/resumeButtons.js
JavaScript
gpl-3.0
808
package NewAI; import Events.Event; import GUI.CurrentSetup; import Mapviewer.TiledMapReader.JsonClasses.TileObject; import NewAI.AILogic.AILogicRunner; import NewAI.BaseClasses.MyBody; import NewAI.NewPathfinding.Grid2d; import Sprites.Sprites; import org.dyn4j.geometry.Geometry; import org.dyn4j.geometry.MassType; import org.dyn4j.geometry.Vector2; import java.time.LocalTime; import java.util.List; import java.util.Random; public class MyNpc extends MyBody { private volatile List<Grid2d.MapNode> _path; private Grid2d.MapNode _cDestination; private Grid2d _pathfinder; private Thread _pathGen = new Thread(); private final boolean _debugOn = false; private int _peedomiter;//pee meter peeDomiter aka how much does the npc want to pee private static int _peedomiterMax = CurrentSetup.maxPee; private Random rand = new Random(); private LocalTime _timeStayingAtEvent; private TileObject _objectToGoTo; public boolean reconciderEvents; public MyNpc(double x, double y, Grid2d pathfinder) { super(x, y); Sprite = Sprites.Bezoekers[new Random().nextInt(Sprites.Bezoekers.length)]; _pathfinder = pathfinder; reconciderEvents = false; _timeStayingAtEvent = LocalTime.of(0,0,0); _peedomiter = (int) (Math.random() * _peedomiterMax); addFixture(Geometry.createCircle(Sprite.getWidth())); setMass(MassType.FIXED_ANGULAR_VELOCITY); setAutoSleepingEnabled(false); translate(x, y); } public void setDestination(double x, double y) { setDestination(new Vector2(x, y)); } public void setDestination(Vector2 destination) { Vector2 vector = new Vector2(getWorldCenter(), destination); transform.setRotation(vector.getDirection() + Math.PI); setLinearVelocity(vector.multiply(25)); } private MyPoint whereDoIWantToGo() { if (_debugOn) System.out.println("updating whereDoIWantToGo"); AILogicRunner aiLogicRunner = CurrentSetup.aiLogicRunner; if (_peedomiter > _peedomiterMax) { _objectToGoTo = aiLogicRunner.returnRandomToilet(); _peedomiter = 0; } else { boolean switchToNewEventChance = CurrentSetup.eventSwitchChance > Math.random(); if (CurrentSetup.aiLogicRunner._time.isAfter(_timeStayingAtEvent)||switchToNewEventChance||reconciderEvents) { reconciderEvents = false; Event eventToGoTo = aiLogicRunner.giveActualEventDestination(); if (eventToGoTo!=null){ _timeStayingAtEvent = CurrentSetup.aiLogicRunner.jaredDateToLocalTime( eventToGoTo.getTime().getEndDate()); _objectToGoTo = CurrentSetup.aiLogicRunner.get_podia().get(eventToGoTo.getPodium() - 1); } } } if (_objectToGoTo == null) return null; return new MyPoint((_objectToGoTo.getX() + rand.nextInt(_objectToGoTo.getWidth()))/32, (_objectToGoTo.getY() - rand.nextInt(_objectToGoTo.getHeight()))/32); } private void generatePath() { MyPoint togoto = whereDoIWantToGo(); if (togoto == null) return; if (inArea(togoto.x, togoto.y)) return; if (!_pathGen.isAlive()) { _pathGen = new Thread(() -> { int xStart = (int) getWorldCenter().x / 32; int yStart = (int) getWorldCenter().y / 32; _path = _pathfinder.findPath(xStart, yStart, togoto.x, togoto.y); if (_path == null && _debugOn) System.out.println("No path found"); }); _pathGen.start(); } } public void AddPee() { _peedomiter++; } public void update() { if (_path == null|| _peedomiter > _peedomiterMax)//todo kijken of hier bugs ontstaan generatePath(); else { if (_cDestination == null) _cDestination = _path.get(0); if (inArea(_cDestination.getX(), _cDestination.getY())) { setLinearVelocity(0, 0); _path.remove(0); if (_path.size() > 0) _cDestination = _path.get(0); else _path = null; } } if (_cDestination != null) setDestination(_cDestination.getX() * 32, _cDestination.getY() * 32); } private boolean inArea(int x, int y) { Vector2 center = getWorldCenter(); double mX = Math.round(center.x / 32); double mY = Math.round(center.y / 32); return mX == x && mY == y; } class MyPoint { int x, y; MyPoint(int x, int y) { this.x = x; this.y = y; } } }
jipjan/ProjectFestival
src/NewAI/MyNpc.java
Java
gpl-3.0
4,812
/* Copyright (c) 2005-2016 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include "tbb/tbb_config.h" #if !__TBB_WIN8UI_SUPPORT && defined(_WIN32) #define _CRT_SECURE_NO_DEPRECATE 1 #define __TBB_NO_IMPLICIT_LINKAGE 1 #include <windows.h> #include <new> #include <stdio.h> #include "tbb_function_replacement.h" #include "tbb/tbb_config.h" #include "tbb/tbb_stddef.h" #include "../tbb/tbb_assert_impl.h" inline UINT_PTR Ptr2Addrint(LPVOID ptr) { Int2Ptr i2p; i2p.lpv = ptr; return i2p.uip; } inline LPVOID Addrint2Ptr(UINT_PTR ptr) { Int2Ptr i2p; i2p.uip = ptr; return i2p.lpv; } // Is the distance between addr1 and addr2 smaller than dist inline bool IsInDistance(UINT_PTR addr1, UINT_PTR addr2, __int64 dist) { __int64 diff = addr1>addr2 ? addr1-addr2 : addr2-addr1; return diff<dist; } /* * When inserting a probe in 64 bits process the distance between the insertion * point and the target may be bigger than 2^32. In this case we are using * indirect jump through memory where the offset to this memory location * is smaller than 2^32 and it contains the absolute address (8 bytes). * * This class is used to hold the pages used for the above trampolines. * Since this utility will be used to replace malloc functions this implementation * doesn't allocate memory dynamically. * * The struct MemoryBuffer holds the data about a page in the memory used for * replacing functions in Intel64 where the target is too far to be replaced * with a short jump. All the calculations of m_base and m_next are in a multiple * of SIZE_OF_ADDRESS (which is 8 in Win64). */ class MemoryProvider { private: struct MemoryBuffer { UINT_PTR m_base; // base address of the buffer UINT_PTR m_next; // next free location in the buffer DWORD m_size; // size of buffer // Default constructor MemoryBuffer() : m_base(0), m_next(0), m_size(0) {} // Constructor MemoryBuffer(void *base, DWORD size) { m_base = Ptr2Addrint(base); m_next = m_base; m_size = size; } }; MemoryBuffer *CreateBuffer(UINT_PTR addr) { // No more room in the pages database if (m_lastBuffer - m_pages == MAX_NUM_BUFFERS) return 0; void *newAddr = Addrint2Ptr(addr); // Get information for the region which the given address belongs to MEMORY_BASIC_INFORMATION memInfo; if (VirtualQuery(newAddr, &memInfo, sizeof(memInfo)) != sizeof(memInfo)) return 0; for(;;) { // The new address to check is beyond the current region and aligned to allocation size newAddr = Addrint2Ptr( (Ptr2Addrint(memInfo.BaseAddress) + memInfo.RegionSize + m_allocSize) & ~(UINT_PTR)(m_allocSize-1) ); // Check that the address is in the right distance. // VirtualAlloc can only round the address down; so it will remain in the right distance if (!IsInDistance(addr, Ptr2Addrint(newAddr), MAX_DISTANCE)) break; if (VirtualQuery(newAddr, &memInfo, sizeof(memInfo)) != sizeof(memInfo)) break; if (memInfo.State == MEM_FREE && memInfo.RegionSize >= m_allocSize) { // Found a free region, try to allocate a page in this region void *newPage = VirtualAlloc(newAddr, m_allocSize, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE); if (!newPage) break; // Add the new page to the pages database MemoryBuffer *pBuff = new (m_lastBuffer) MemoryBuffer(newPage, m_allocSize); ++m_lastBuffer; return pBuff; } } // Failed to find a buffer in the distance return 0; } public: MemoryProvider() { SYSTEM_INFO sysInfo; GetSystemInfo(&sysInfo); m_allocSize = sysInfo.dwAllocationGranularity; m_lastBuffer = &m_pages[0]; } // We can't free the pages in the destructor because the trampolines // are using these memory locations and a replaced function might be called // after the destructor was called. ~MemoryProvider() { } // Return a memory location in distance less than 2^31 from input address UINT_PTR GetLocation(UINT_PTR addr) { MemoryBuffer *pBuff = m_pages; for (; pBuff<m_lastBuffer && IsInDistance(pBuff->m_next, addr, MAX_DISTANCE); ++pBuff) { if (pBuff->m_next < pBuff->m_base + pBuff->m_size) { UINT_PTR loc = pBuff->m_next; pBuff->m_next += MAX_PROBE_SIZE; return loc; } } pBuff = CreateBuffer(addr); if(!pBuff) return 0; UINT_PTR loc = pBuff->m_next; pBuff->m_next += MAX_PROBE_SIZE; return loc; } private: MemoryBuffer m_pages[MAX_NUM_BUFFERS]; MemoryBuffer *m_lastBuffer; DWORD m_allocSize; }; static MemoryProvider memProvider; // Compare opcodes from dictionary (str1) and opcodes from code (str2) // str1 might contain '*' to mask addresses // RETURN: NULL if opcodes did not match, string length of str1 on success size_t compareStrings( const char *str1, const char *str2 ) { size_t str1Length = strlen(str1); for (size_t i=0; i<str1Length; i++){ if( str1[i] != '*' && str1[i] != str2[i] ) return 0; } return str1Length; } // Check function prologue with known prologues from the dictionary // opcodes - dictionary // inpAddr - pointer to function prologue // Dictionary contains opcodes for several full asm instructions // + one opcode byte for the next asm instruction for safe address processing // RETURN: number of bytes for safe bytes replacement (matched_pattern/2-1) UINT CheckOpcodes( const char ** opcodes, void *inpAddr, bool abortOnError ) { static size_t opcodesStringsCount = 0; static size_t maxOpcodesLength = 0; static size_t opcodes_pointer = (size_t)opcodes; char opcodeString[61]; size_t i; size_t result; // Get the values for static variables // max length and number of patterns if( !opcodesStringsCount || opcodes_pointer != (size_t)opcodes ){ while( *(opcodes + opcodesStringsCount)!= NULL ){ if( (i=strlen(*(opcodes + opcodesStringsCount))) > maxOpcodesLength ) maxOpcodesLength = i; opcodesStringsCount++; } opcodes_pointer = (size_t)opcodes; __TBB_ASSERT( maxOpcodesLength < 61, "Limit is 30 opcodes/60 symbols per pattern" ); } // Translate prologue opcodes to string format to compare for( i=0; i< maxOpcodesLength/2; i++ ){ sprintf( opcodeString + 2*i, "%.2X", *((unsigned char*)inpAddr+i) ); } opcodeString[maxOpcodesLength] = 0; // Compare translated opcodes with patterns for( i=0; i< opcodesStringsCount; i++ ){ result = compareStrings( opcodes[i],opcodeString ); if( result ) return (UINT)(result/2-1); } if (abortOnError) { // Impossibility to find opcodes in the dictionary is a serious issue, // as if we unable to call original function, leak or crash is expected result. __TBB_ASSERT_RELEASE( false, "CheckOpcodes failed" ); } return 0; } // Insert jump relative instruction to the input address // RETURN: the size of the trampoline or 0 on failure static DWORD InsertTrampoline32(void *inpAddr, void *targetAddr, const char ** opcodes, void** storedAddr) { UINT opcodesNumber = SIZE_OF_RELJUMP; UINT_PTR srcAddr = Ptr2Addrint(inpAddr); UINT_PTR tgtAddr = Ptr2Addrint(targetAddr); // Check that the target fits in 32 bits if (!IsInDistance(srcAddr, tgtAddr, MAX_DISTANCE)) return 0; UINT_PTR offset; UINT offset32; UCHAR *codePtr = (UCHAR *)inpAddr; if ( storedAddr ){ // If requested, store original function code if ( *codePtr == 0xE9 ){ // JMP relative instruction // For the special case when a system function consists of a single near jump, // instead of moving it somewhere we use the target of the jump as the original function. unsigned offsetInJmp = *(unsigned*)(codePtr + 1); *storedAddr = (void*)(srcAddr + offsetInJmp + SIZE_OF_RELJUMP); }else{ opcodesNumber = CheckOpcodes( opcodes, inpAddr, /*abortOnError=*/true ); __TBB_ASSERT_RELEASE( opcodesNumber >= SIZE_OF_RELJUMP, "Incorrect bytecode pattern?" ); UINT_PTR strdAddr = memProvider.GetLocation(srcAddr); if (!strdAddr) return 0; *storedAddr = Addrint2Ptr(strdAddr); // Set 'executable' flag for original instructions in the new place DWORD pageFlags = PAGE_EXECUTE_READWRITE; if (!VirtualProtect(*storedAddr, MAX_PROBE_SIZE, pageFlags, &pageFlags)) return 0; // Copy original instructions to the new place memcpy(*storedAddr, codePtr, opcodesNumber); // Set jump to the code after replacement offset = srcAddr - strdAddr - SIZE_OF_RELJUMP; offset32 = (UINT)((offset & 0xFFFFFFFF)); *((UCHAR*)*storedAddr+opcodesNumber) = 0xE9; memcpy(((UCHAR*)*storedAddr+opcodesNumber+1), &offset32, sizeof(offset32)); } } // The following will work correctly even if srcAddr>tgtAddr, as long as // address difference is less than 2^31, which is guaranteed by IsInDistance. offset = tgtAddr - srcAddr - SIZE_OF_RELJUMP; offset32 = (UINT)(offset & 0xFFFFFFFF); // Insert the jump to the new code *codePtr = 0xE9; memcpy(codePtr+1, &offset32, sizeof(offset32)); // Fill the rest with NOPs to correctly see disassembler of old code in debugger. for( unsigned i=SIZE_OF_RELJUMP; i<opcodesNumber; i++ ){ *(codePtr+i) = 0x90; } return SIZE_OF_RELJUMP; } // This function is called when the offset doesn't fit in 32 bits // 1 Find and allocate a page in the small distance (<2^31) from input address // 2 Put jump RIP relative indirect through the address in the close page // 3 Put the absolute address of the target in the allocated location // RETURN: the size of the trampoline or 0 on failure static DWORD InsertTrampoline64(void *inpAddr, void *targetAddr, const char ** opcodes, void** storedAddr) { UINT opcodesNumber = SIZE_OF_INDJUMP; UINT_PTR srcAddr = Ptr2Addrint(inpAddr); UINT_PTR tgtAddr = Ptr2Addrint(targetAddr); // Get a location close to the source address UINT_PTR location = memProvider.GetLocation(srcAddr); if (!location) return 0; UINT_PTR offset; UINT offset32; UCHAR *codePtr = (UCHAR *)inpAddr; // Fill the location UINT_PTR *locPtr = (UINT_PTR *)Addrint2Ptr(location); *locPtr = tgtAddr; if ( storedAddr ){ // If requested, store original function code if ( *codePtr == 0xE9 ){ // JMP relative instruction // For the special case when a system function consists of a single near jump, // instead of moving it somewhere we use the target of the jump as the original function. unsigned offsetInJmp = *(unsigned*)(codePtr + 1); *storedAddr = (void*)(srcAddr + offsetInJmp + SIZE_OF_RELJUMP); }else{ opcodesNumber = CheckOpcodes( opcodes, inpAddr, /*abortOnError=*/true ); __TBB_ASSERT_RELEASE( opcodesNumber >= SIZE_OF_INDJUMP, "Incorrect bytecode pattern?" ); UINT_PTR strdAddr = memProvider.GetLocation(srcAddr); if (!strdAddr) return 0; *storedAddr = Addrint2Ptr(strdAddr); // Set 'executable' flag for original instructions in the new place DWORD pageFlags = PAGE_EXECUTE_READWRITE; if (!VirtualProtect(*storedAddr, MAX_PROBE_SIZE, pageFlags, &pageFlags)) return 0; // Copy original instructions to the new place memcpy(*storedAddr, codePtr, opcodesNumber); // Set jump to the code after replacement. It is within the distance of relative jump! offset = srcAddr - strdAddr - SIZE_OF_RELJUMP; offset32 = (UINT)((offset & 0xFFFFFFFF)); *((UCHAR*)*storedAddr+opcodesNumber) = 0xE9; memcpy(((UCHAR*)*storedAddr+opcodesNumber+1), &offset32, sizeof(offset32)); } } // Fill the buffer offset = location - srcAddr - SIZE_OF_INDJUMP; offset32 = (UINT)(offset & 0xFFFFFFFF); *(codePtr) = 0xFF; *(codePtr+1) = 0x25; memcpy(codePtr+2, &offset32, sizeof(offset32)); // Fill the rest with NOPs to correctly see disassembler of old code in debugger. for( unsigned i=SIZE_OF_INDJUMP; i<opcodesNumber; i++ ){ *(codePtr+i) = 0x90; } return SIZE_OF_INDJUMP; } // Insert a jump instruction in the inpAddr to the targetAddr // 1. Get the memory protection of the page containing the input address // 2. Change the memory protection to writable // 3. Call InsertTrampoline32 or InsertTrampoline64 // 4. Restore memory protection // RETURN: FALSE on failure, TRUE on success static bool InsertTrampoline(void *inpAddr, void *targetAddr, const char ** opcodes, void** origFunc) { DWORD probeSize; // Change page protection to EXECUTE+WRITE DWORD origProt = 0; if (!VirtualProtect(inpAddr, MAX_PROBE_SIZE, PAGE_EXECUTE_WRITECOPY, &origProt)) return FALSE; probeSize = InsertTrampoline32(inpAddr, targetAddr, opcodes, origFunc); if (!probeSize) probeSize = InsertTrampoline64(inpAddr, targetAddr, opcodes, origFunc); // Restore original protection VirtualProtect(inpAddr, MAX_PROBE_SIZE, origProt, &origProt); if (!probeSize) return FALSE; FlushInstructionCache(GetCurrentProcess(), inpAddr, probeSize); FlushInstructionCache(GetCurrentProcess(), origFunc, probeSize); return TRUE; } // Routine to replace the functions // TODO: replace opcodesNumber with opcodes and opcodes number to check if we replace right code. FRR_TYPE ReplaceFunctionA(const char *dllName, const char *funcName, FUNCPTR newFunc, const char ** opcodes, FUNCPTR* origFunc) { // Cache the results of the last search for the module // Assume that there was no DLL unload between static char cachedName[MAX_PATH+1]; static HMODULE cachedHM = 0; if (!dllName || !*dllName) return FRR_NODLL; if (!cachedHM || strncmp(dllName, cachedName, MAX_PATH) != 0) { // Find the module handle for the input dll HMODULE hModule = GetModuleHandleA(dllName); if (hModule == 0) { // Couldn't find the module with the input name cachedHM = 0; return FRR_NODLL; } cachedHM = hModule; strncpy(cachedName, dllName, MAX_PATH); } FARPROC inpFunc = GetProcAddress(cachedHM, funcName); if (inpFunc == 0) { // Function was not found return FRR_NOFUNC; } if (!InsertTrampoline((void*)inpFunc, (void*)newFunc, opcodes, (void**)origFunc)){ // Failed to insert the trampoline to the target address return FRR_FAILED; } return FRR_OK; } FRR_TYPE ReplaceFunctionW(const wchar_t *dllName, const char *funcName, FUNCPTR newFunc, const char ** opcodes, FUNCPTR* origFunc) { // Cache the results of the last search for the module // Assume that there was no DLL unload between static wchar_t cachedName[MAX_PATH+1]; static HMODULE cachedHM = 0; if (!dllName || !*dllName) return FRR_NODLL; if (!cachedHM || wcsncmp(dllName, cachedName, MAX_PATH) != 0) { // Find the module handle for the input dll HMODULE hModule = GetModuleHandleW(dllName); if (hModule == 0) { // Couldn't find the module with the input name cachedHM = 0; return FRR_NODLL; } cachedHM = hModule; wcsncpy(cachedName, dllName, MAX_PATH); } FARPROC inpFunc = GetProcAddress(cachedHM, funcName); if (inpFunc == 0) { // Function was not found return FRR_NOFUNC; } if (!InsertTrampoline((void*)inpFunc, (void*)newFunc, opcodes, (void**)origFunc)){ // Failed to insert the trampoline to the target address return FRR_FAILED; } return FRR_OK; } bool IsPrologueKnown(HMODULE module, const char *funcName, const char **opcodes) { FARPROC inpFunc = GetProcAddress(module, funcName); if (!inpFunc) return false; return CheckOpcodes( opcodes, (void*)inpFunc, /*abortOnError=*/false ) != 0; } #endif /* !__TBB_WIN8UI_SUPPORT && defined(_WIN32) */
IMP-Engine/Engine
external/tbb/src/tbbmalloc/tbb_function_replacement.cpp
C++
gpl-3.0
17,343
/* * Copyright 2012-2020 Rafal Lewczuk <rafal.lewczuk@jitlogic.com> * <p/> * This is free software. You can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * <p/> * This software is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * <p/> * You should have received a copy of the GNU General Public License * along with this software. If not, see <http://www.gnu.org/licenses/>. */ package com.jitlogic.zorka.core.spy.ltracer; import com.jitlogic.zorka.common.tracedata.DTraceContext; import com.jitlogic.zorka.core.spy.tuner.TraceTuningStats; import com.jitlogic.zorka.core.spy.tuner.TracerTuner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public abstract class TraceHandler { protected final Logger log = LoggerFactory.getLogger(this.getClass()); /** Default long call threshold for automated tracer tuning: 10ms */ public static final long TUNING_DEFAULT_LCALL_THRESHOLD = 10000000L; /** Default handler-tuner exchange interval. */ public static final long TUNING_DEFAULT_EXCH_INTERVAL = 30 * 1000000000L; /** */ public static final long TUNING_EXCHANGE_CALLS_DEFV = 1048576; protected static boolean tuningEnabled = false; /** Threshold above which method call will be considered long-duration. */ protected static long tuningLongThreshold = TUNING_DEFAULT_LCALL_THRESHOLD; /** Interval between handler-tuner exchanges. */ protected static long tuningExchInterval = TUNING_DEFAULT_EXCH_INTERVAL; /** Minimum number of calls required to initiate tuning stats exchange */ private static long tuningExchangeMinCalls = TUNING_EXCHANGE_CALLS_DEFV; /** Default: ~0.25ms */ public final static long DEFAULT_MIN_METHOD_TIME = 262144; /** Minimum default method execution time required to attach method to trace. */ protected static long minMethodTime = DEFAULT_MIN_METHOD_TIME; protected static int maxAttrLen = 8192; /** Maximum number of records inside trace */ protected static int maxTraceRecords = 4096; /** Number of registered trace calls that will force trace submission regardless of execution time. */ protected static int minTraceCalls = 262144; protected boolean disabled; protected long tunCalls = 0; protected TracerTuner tuner; protected TraceTuningStats tunStats = null; protected long tunLastExchange = 0; public static final int LONG_PENALTY = -1024; public static final int ERROR_PENALTY = -256; public abstract void traceBegin(int traceId, long clock, int flags); /** * Attaches attribute to current trace record (or any other record up the call stack). * * @param traceId positive number (trace id) if attribute has to be attached to a top record of specific * trace, 0 if attribute has to be attached to a top record of any trace, -1 if attribute * has to be attached to current method; * @param attrId attribute ID * @param attrVal attribute value */ public abstract void newAttr(int traceId, int attrId, Object attrVal); public void disable() { disabled = true; } public void enable() { disabled = false; } protected void tuningProbe(int mid, long tstamp, long ttime) { if (tunStats == null || (tstamp > tunLastExchange + tuningExchInterval && tunCalls > tuningExchangeMinCalls)) { tuningExchange(tstamp); } tunCalls++; if (tuningEnabled) { if (ttime < minMethodTime) { if (!tunStats.markRank(mid, 1)) { tuningExchange(tstamp); } } else if (ttime > tuningLongThreshold) { tunStats.markRank(mid, -1 * (int)(ttime >>> 18)); } } } private void tuningExchange(long tstamp) { if (tunStats != null) { tunStats.setThreadId(Thread.currentThread().getId()); tunStats.setCalls(tunCalls); tunStats.setTstamp(tstamp); tunCalls = 0; } tunStats = tuner.exchange(tunStats); tunLastExchange = tstamp; } /** * Sets minimum trace execution time for currently recorded trace. * If there is no trace being recorded just yet, this method will * have no effect. * * @param minimumTraceTime (in nanoseconds) */ public abstract void setMinimumTraceTime(long minimumTraceTime); public abstract void markTraceFlags(int traceId, int flag); public abstract void markRecordFlags(int flag); public abstract boolean isInTrace(int traceId); public abstract void traceReturn(long tstamp); public abstract void traceEnter(int mid, long tstamp); public abstract void traceError(Object e, long tstamp); public abstract DTraceContext getDTraceState(); public abstract DTraceContext parentDTraceState(); public abstract void setDTraceState(DTraceContext state); public static long getTuningExchangeMinCalls() { return tuningExchangeMinCalls; } public static void setTuningExchangeMinCalls(long tuningExchangeMinCalls) { TraceHandler.tuningExchangeMinCalls = tuningExchangeMinCalls; } public static boolean isTuningEnabled() { return tuningEnabled; } public static void setTuningEnabled(boolean tuningEnabled) { TraceHandler.tuningEnabled = tuningEnabled; } public static long getTuningLongThreshold() { return tuningLongThreshold; } public static void setTuningLongThreshold(long tuningLongThreshold) { TraceHandler.tuningLongThreshold = tuningLongThreshold; } public static long getTuningDefaultExchInterval() { return tuningExchInterval; } public static void setTuningDefaultExchInterval(long tuningDefaultExchInterval) { TraceHandler.tuningExchInterval = tuningDefaultExchInterval; } public static long getMinMethodTime() { return minMethodTime; } public static void setMinMethodTime(long methodTime) { minMethodTime = methodTime; } public static int getMaxTraceRecords() { return maxTraceRecords; } public static void setMaxTraceRecords(int traceSize) { maxTraceRecords = traceSize; } public static int getMinTraceCalls() { return minTraceCalls; } public static void setMinTraceCalls(int traceCalls) { minTraceCalls = traceCalls; } }
jitlogic/zorka
zorka-core/src/main/java/com/jitlogic/zorka/core/spy/ltracer/TraceHandler.java
Java
gpl-3.0
6,847
package com.idega.idegaweb.egov.bpm.data; import org.jbpm.module.def.ModuleDefinition; import org.jbpm.module.exe.ModuleInstance; /** * @deprecated this is held here only to support older processes, that contains this definition * @author <a href="mailto:civilis@idega.com">Vytautas Čivilis</a> * @version $Revision: 1.4 $ Last modified: $Date: 2009/04/29 13:38:11 $ by $Author: civilis $ */ @Deprecated public class AppProcBindDefinition extends ModuleDefinition { private static final long serialVersionUID = 6504030191381296426L; @Override public ModuleInstance createInstance() { return null; } }
idega/is.idega.idegaweb.egov.bpm
src/java/com/idega/idegaweb/egov/bpm/data/AppProcBindDefinition.java
Java
gpl-3.0
617
package sistemaReserva; public class Persona { protected String nombre; protected String apellido; protected String tipoDocumento; protected String numeroDocumento; protected String direccion; protected String telefono; protected String email; protected String estado;//ACTIVA | INACTIVA public Persona(String nom, String ape, String tDoc, String nDoc, String dir, String tel, String eMail) { nombre = nom; apellido = ape; tipoDocumento = tDoc; numeroDocumento = nDoc; direccion = dir; telefono = tel; email = eMail; estado = "ACTIVO"; } public String getNombre() { return nombre; } public void setNombre(String nombre) { this.nombre = nombre; } public String getApellido() { return apellido; } public void setApellido(String apellido) { this.apellido = apellido; } public String getTipoDocumento() { return tipoDocumento; } public void setTipoDocumento(String tipoDocumento) { this.tipoDocumento = tipoDocumento; } public String getNumeroDocumento() { return numeroDocumento; } public void setNumeroDocumento(String numeroDocumento) { this.numeroDocumento = numeroDocumento; } public String getDireccion() { return direccion; } public void setDireccion(String direccion) { this.direccion = direccion; } public String getTelefono() { return telefono; } public void setTelefono(String telefono) { this.telefono = telefono; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getEstado() { return estado; } public void setEstado(String estado) { this.estado = estado; } //negocio public boolean esTuDocumento(String tipoDoc, String numDoc) { return (tipoDocumento.equals(tipoDoc) && numeroDocumento.equals(numDoc)); } public void darBaja() { estado = "INACTIVO"; } }
dforce2055/ReservaHotel
src/sistemaReserva/Persona.java
Java
gpl-3.0
2,110
package net.gazeplay.games.memory; import javafx.geometry.Dimension2D; import javafx.scene.image.Image; import lombok.AllArgsConstructor; import lombok.Data; import lombok.extern.slf4j.Slf4j; import net.gazeplay.GameLifeCycle; import net.gazeplay.IGameContext; import net.gazeplay.commons.configuration.Configuration; import net.gazeplay.commons.utils.games.ImageLibrary; import net.gazeplay.commons.utils.games.ImageUtils; import net.gazeplay.commons.utils.games.Utils; import net.gazeplay.commons.utils.stats.Stats; import java.util.*; @Slf4j public class Memory implements GameLifeCycle { private static final float cardRatio = 0.75f; private static final int minHeight = 30; public enum MemoryGameType { LETTERS, NUMBERS, DEFAULT } @Data @AllArgsConstructor public static class RoundDetails { public final List<MemoryCard> cardList; } private int nbRemainingPeers; private final IGameContext gameContext; private final int nbLines; private final int nbColumns; private final Stats stats; private ImageLibrary imageLibrary; /* * HashMap of images selected for this game and their associated id The id is the same for the 2 same images */ public HashMap<Integer, Image> images; public RoundDetails currentRoundDetails; public int nbTurnedCards; private final boolean isOpen; public Memory(final MemoryGameType gameType, final IGameContext gameContext, final int nbLines, final int nbColumns, final Stats stats, final boolean isOpen) { super(); this.isOpen = isOpen; final int cardsCount = nbLines * nbColumns; if ((cardsCount & 1) != 0) { // nbLines * nbColumns must be a multiple of 2 throw new IllegalArgumentException("Cards count must be an even number in this game"); } this.nbRemainingPeers = (nbLines * nbColumns) / 2; this.gameContext = gameContext; this.nbLines = nbLines; this.nbColumns = nbColumns; this.stats = stats; if (gameType == MemoryGameType.LETTERS) { this.imageLibrary = ImageUtils.createCustomizedImageLibrary(null, "common/letters"); } else if (gameType == MemoryGameType.NUMBERS) { this.imageLibrary = ImageUtils.createCustomizedImageLibrary(null, "common/numbers"); } else { this.imageLibrary = ImageUtils.createImageLibrary(Utils.getImagesSubDirectory("magiccards"), Utils.getImagesSubDirectory("default")); } } HashMap<Integer, Image> pickRandomImages() { final int cardsCount = nbColumns * nbLines; final HashMap<Integer, Image> res = new HashMap<>(); final Set<Image> images = imageLibrary.pickMultipleRandomDistinctImages(cardsCount / 2); int i = 0; for (final Image image : images) { res.put(i, image); i++; } return res; } @Override public void launch() { final Configuration config = gameContext.getConfiguration(); final int cardsCount = nbColumns * nbLines; images = pickRandomImages(); final List<MemoryCard> cardList = createCards(images, config); nbRemainingPeers = cardsCount / 2; currentRoundDetails = new RoundDetails(cardList); gameContext.getChildren().addAll(cardList); stats.notifyNewRoundReady(); } @Override public void dispose() { if (currentRoundDetails != null) { if (currentRoundDetails.cardList != null) { gameContext.getChildren().removeAll(currentRoundDetails.cardList); } currentRoundDetails = null; } } public void removeSelectedCards() { if (this.currentRoundDetails == null) { return; } final List<MemoryCard> cardsToHide = new ArrayList<>(); for (final MemoryCard pictureCard : this.currentRoundDetails.cardList) { if (pictureCard.isTurned()) { cardsToHide.add(pictureCard); } } nbRemainingPeers = nbRemainingPeers - 1; // remove all turned cards gameContext.getChildren().removeAll(cardsToHide); } private List<MemoryCard> createCards(final HashMap<Integer, Image> im, final Configuration config) { final javafx.geometry.Dimension2D gameDimension2D = gameContext.getGamePanelDimensionProvider().getDimension2D(); log.debug("Width {} ; height {}", gameDimension2D.getWidth(), gameDimension2D.getHeight()); final double cardHeight = computeCardHeight(gameDimension2D, nbLines); final double cardWidth = cardHeight * cardRatio; log.debug("cardWidth {} ; cardHeight {}", cardWidth, cardHeight); final double width = computeCardWidth(gameDimension2D, nbColumns) - cardWidth; log.debug("width {} ", width); final List<MemoryCard> result = new ArrayList<>(); // HashMap <index, number of times the index was used > final HashMap<Integer, Integer> indUsed = new HashMap<>(); indUsed.clear(); final int fixationlength = config.getFixationLength(); for (int currentLineIndex = 0; currentLineIndex < nbLines; currentLineIndex++) { for (int currentColumnIndex = 0; currentColumnIndex < nbColumns; currentColumnIndex++) { final double positionX = width / 2d + (width + cardWidth) * currentColumnIndex; final double positionY = minHeight / 2d + (minHeight + cardHeight) * currentLineIndex; log.debug("positionX : {} ; positionY : {}", positionX, positionY); final int id = getRandomValue(indUsed); if (indUsed.containsKey(id)) { indUsed.replace(id, 1, 2); } else { indUsed.put(id, 1); } final Image image = images.get(id); final MemoryCard card = new MemoryCard(positionX, positionY, cardWidth, cardHeight, image, id, gameContext, stats, this, fixationlength, isOpen); result.add(card); } } return result; } private static double computeCardHeight(final Dimension2D gameDimension2D, final int nbLines) { return gameDimension2D.getHeight() * 0.9 / nbLines; } private static double computeCardWidth(final Dimension2D gameDimension2D, final int nbColumns) { return gameDimension2D.getWidth() / nbColumns; } private int getRandomValue(final HashMap<Integer, Integer> indUsed) { int value; final Random rdm = new Random(); do { value = rdm.nextInt(images.size()); } while ((!images.containsKey(value)) || (indUsed.containsKey(value) && (indUsed.get(value) == 2))); // While selected image is already used 2 times (if it appears ) return value; } public int getnbRemainingPeers() { return nbRemainingPeers; } }
YannRobert/GazePlay
gazeplay-games/src/main/java/net/gazeplay/games/memory/Memory.java
Java
gpl-3.0
7,082
/* * Copyright (C) 2016-2021 phantombot.github.io/PhantomBot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /** * lang.js * * Provide a language API * Use the $.lang API * * NOTE: Reading from/writing to the lang data directly is not possbile anymore! * Use the register(), exists() and get() functions! */ (function() { var data = [], curLang = ($.inidb.exists('settings', 'lang') ? $.inidb.get('settings', 'lang') : 'english'); /** * @function load */ function load(force) { $.bot.loadScriptRecursive('./lang/english', true, (force ? force : false)); if (curLang != 'english') { $.bot.loadScriptRecursive('./lang/' + curLang, true, (force ? force : false)); } if ($.isDirectory('./scripts/lang/custom')) { $.bot.loadScriptRecursive('./lang/custom', true, (force ? force : false)); } // Set "response_@chat" to true if it hasn't been set yet, so the bot isn't muted when using a fresh install if (!$.inidb.exists('settings', 'response_@chat')) { $.setIniDbBoolean('settings', 'response_@chat', true); } } /** * @function register * @export $.lang * @param {string} key * @param {string} string */ function register(key, string) { if (key && string) { data[key.toLowerCase()] = string; } if (key && string.length === 0) { data[key.toLowerCase()] = '<<EMPTY_PLACEHOLDER>>'; } } /** * @function get * @export $.lang * @param {string} key * @returns {string} */ function get(key) { var string = data[key.toLowerCase()], i; if (string === undefined) { $.log.warn('Lang string for key "' + key + '" was not found.'); return ''; } if (string == '<<EMPTY_PLACEHOLDER>>') { return ''; } for (i = 1; i < arguments.length; i++) { while (string.indexOf("$" + i) >= 0) { string = string.replace("$" + i, arguments[i]); } } return string; } /** * @function paramCount * @export $.lang * @param {string} key * @returns {Number} */ function paramCount(key) { var string = data[key.toLowerCase()], i, ctr = 0; if (!string) { return 0; } for (i = 1; i < 99; i++) { if (string.indexOf("$" + i) >= 0) { ctr++; } else { break; } } return ctr; } /** * @function exists * @export $.lang * @param {string} key * @returns {boolean} */ function exists(key) { return (data[key.toLowerCase()]); } /** * @event command */ $.bind('command', function(event) { var sender = event.getSender().toLowerCase(), command = event.getCommand(), args = event.getArgs(), action = args[0], inversedState; /** * @commandpath lang [language name] - Get or optionally set the current language (use folder name from "./lang" directory); */ if (command.equalsIgnoreCase('lang')) { if (!action) { $.say($.whisperPrefix(sender) + get('lang.curlang', curLang)); } else { action = action.toLowerCase(); if (!$.fileExists('./scripts/lang/' + action + '/main.js')) { $.say($.whisperPrefix(sender) + get('lang.lang.404')); } else { $.inidb.set('settings', 'lang', action); curLang = action; load(true); $.say($.whisperPrefix(sender) + get('lang.lang.changed', action)); } } } /** * @commandpath mute - Toggle muting the bot in the chat */ if (command.equalsIgnoreCase('mute')) { inversedState = !$.getIniDbBoolean('settings', 'response_@chat'); $.setIniDbBoolean('settings', 'response_@chat', inversedState); $.reloadMisc(); $.say($.whisperPrefix(sender) + (inversedState ? get('lang.response.enabled') : get('lang.response.disabled'))); } /** * @commandpath toggleme - Toggle prepending chat output with "/me". */ if (command.equalsIgnoreCase('toggleme')) { inversedState = !$.getIniDbBoolean('settings', 'response_action'); $.setIniDbBoolean('settings', 'response_action', inversedState); $.reloadMisc(); $.say($.whisperPrefix(sender) + (inversedState ? get('lang.response.action.enabled') : get('lang.response.action.disabled'))); } }); /** * @event initReady */ $.bind('initReady', function() { $.registerChatCommand('./core/lang.js', 'lang', 1); $.registerChatCommand('./core/lang.js', 'mute', 1); $.registerChatCommand('./core/lang.js', 'toggleme', 1); }); /** Export functions to API */ $.lang = { exists: exists, get: get, register: register, paramCount: paramCount }; // Run the load function to enable modules, loaded after lang.js, to access the language strings immediatly load(); })();
Stargamers/PhantomBot
javascript-source/core/lang.js
JavaScript
gpl-3.0
6,046
/* * JasperReports - Free Java Reporting Library. * Copyright (C) 2001 - 2016 TIBCO Software Inc. All rights reserved. * http://www.jaspersoft.com * * Unless you have purchased a commercial license agreement from Jaspersoft, * the following license terms apply: * * This program is part of JasperReports. * * JasperReports is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * JasperReports is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with JasperReports. If not, see <http://www.gnu.org/licenses/>. */ package net.sf.jasperreports.engine; /** * Report elements visitor extended interface that is able to visit deep/nested elements. * * @author Lucian Chirita (lucianc@users.sourceforge.net) */ public interface ElementsVisitor extends JRVisitor { /** * Decides whether this visitor is to visit deep/nested elements. * * @return whether this visitor is to visit deep/nested elements */ boolean visitDeepElements(); }
MHTaleb/Encologim
lib/JasperReport/src/net/sf/jasperreports/engine/ElementsVisitor.java
Java
gpl-3.0
1,422
package org.groebl.sms.ui.popup; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.PhoneNumberUtils; import android.view.View; import android.widget.AdapterView; import com.android.ex.chips.recipientchip.DrawableRecipientChip; import org.groebl.sms.R; import org.groebl.sms.common.utils.KeyboardUtils; import org.groebl.sms.interfaces.ActivityLauncher; import org.groebl.sms.interfaces.RecipientProvider; import org.groebl.sms.ui.base.QKPopupActivity; import org.groebl.sms.ui.view.AutoCompleteContactView; import org.groebl.sms.ui.view.ComposeView; import org.groebl.sms.ui.view.StarredContactsView; public class QKComposeActivity extends QKPopupActivity implements ComposeView.OnSendListener, RecipientProvider, ActivityLauncher, AdapterView.OnItemClickListener { private final String TAG = "QKComposeActivity"; private Context mContext = this; private AutoCompleteContactView mRecipients; private StarredContactsView mStarredContactsView; private ComposeView mCompose; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(R.string.title_compose); mRecipients = (AutoCompleteContactView) findViewById(R.id.compose_recipients); mRecipients.setOnItemClickListener(this); // Get the compose view, and set it up with all the listeners. findViewById(R.id.compose_view_stub).setVisibility(View.VISIBLE); mCompose = (ComposeView) findViewById(R.id.compose_view); mCompose.setActivityLauncher(this); mCompose.setOnSendListener(this); mCompose.setRecipientProvider(this); mStarredContactsView = (StarredContactsView) findViewById(R.id.starred_contacts); mStarredContactsView.setComposeScreenViews(mRecipients, mCompose); // Apply different attachments based on the type. mCompose.loadMessageFromIntent(getIntent()); } @Override protected int getLayoutResource() { return R.layout.activity_qkcompose; } @Override protected void onPause() { super.onPause(); KeyboardUtils.hide(mContext, mCompose); } @Override public void finish() { // Override pending transitions so that we don't see black for a second when QuickReply closes super.finish(); overridePendingTransition(0, 0); } @Override public String[] getRecipientAddresses() { DrawableRecipientChip[] chips = mRecipients.getRecipients(); String[] addresses = new String[chips.length]; for (int i = 0; i < chips.length; i++) { addresses[i] = PhoneNumberUtils.stripSeparators(chips[i].getEntry().getDestination()); } return addresses; } @Override public void onSend(String[] recipients, String body) { // When the SMS is sent, close this activity. finish(); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (!mCompose.onActivityResult(requestCode, resultCode, data)) { // Handle other results here, since the ComposeView didn't handle them. } } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mRecipients.onItemClick(parent, view, position, id); mStarredContactsView.collapse(); mCompose.requestReplyTextFocus(); } }
BennoGAP/notification-forwarder
SMS/src/main/java/org/groebl/sms/ui/popup/QKComposeActivity.java
Java
gpl-3.0
3,554
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package uk.co.ignesco.teb.api; /** * * @author craig */ public class TebProject { public String repoLocation; public String branch; public String workingDirectory; public String authGroup; public ProjectStatus status; public String id; public TebProject() { } public TebProject(String id, String repoLocation, String branch, String workingDirectory, String authGroup, ProjectStatus status) { this.id = id; this.repoLocation = repoLocation; this.branch = branch; this.workingDirectory = workingDirectory; this.authGroup = authGroup; this.status = status; } public String getStatusString() { switch(status) { case active: { return "active"; } case inactive: { return "inactive"; } default: { return ""; } } } }
ignesco/teb
src/main/java/uk/co/ignesco/teb/api/TebProject.java
Java
gpl-3.0
1,055
(function (root, factory) { if (typeof module === 'object' && module.exports) { module.exports = factory(require('jquery'), require('../common/utility')); } else { root.api = factory(root.jQuery, root.utility); } }(this, function ($, util) { // API var self = {}; // Object -> Promise[[Entity]] self.searchEntity = function(query){ return get('/search/entity', { num: 10, q: query }) .then(format) .catch(handleError); // [Entity] -> [Entity] function format(results){ // stringify id & rename keys (`primary_type` -> `primary_ext`; `description` -> `blurb`) return results.map(function(result) { var _result = Object.assign({}, result, { primary_ext: result.primary_ext || result.primary_type, blurb: result.blurb || result.description, id: String(result.id) }); delete _result.primary_type; delete _result.description; return _result; }); } // Error -> [] function handleError(err){ console.error('API request error: ', err); return []; } }; // [EntityWithoutId] -> Promise[[Entity]] self.createEntities = function(entities){ return post('/entities/bulk', formatReq(entities)) .then(formatResp); // [Entity] -> [Entity] function formatReq(entities){ return { data: entities.map(function(entity){ return { type: "entities", attributes: entity }; }) }; }; // [Entity] -> [Entity] function formatResp(resp){ // copy, but stringify id return resp.data.map(function(datum){ return Object.assign( datum.attributes, { id: String(datum.attributes.id)} ); }); } }; // Integer, [Integer] -> Promise[[ListEntity]] self.addEntitiesToList = function(listId, entityIds, reference){ return post('/lists/'+listId+'/entities/bulk', formatReq(entityIds)) .then(formatResp); function formatReq(entityIds){ return { data: entityIds.map(function(id){ return { type: 'entities', id: id }; }).concat({ type: 'references', attributes: reference }) }; }; function formatResp(resp){ return resp.data.map(function(datum){ return util.stringifyValues(datum.attributes); }); } }; // String, Integer -> Promise // helpers function get(url, queryParams){ return fetch(url + qs(queryParams), { headers: headers(), method: 'get', credentials: 'include' // use auth tokens stored in session cookies }).then(jsonify); } function post(url, payload){ return fetch(url, { headers: headers(), method: 'post', credentials: 'include', // use auth tokens stored in session cookies body: JSON.stringify(payload) }).then(jsonify); }; function patch(url, payload){ return fetch(url, { headers: headers(), method: 'PATCH', credentials: 'include', // use auth tokens stored in session cookies body: JSON.stringify(payload) }).then(function(response) { if (response.body) { return jsonify(response); } else { return response; } }); }; function headers(){ return { 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/json', 'Littlesis-Request-Type': 'API', // TODO: retrieve this w/o JQuery 'X-CSRF-Token': $("meta[name='csrf-token']").attr("content") || "" }; } function qs(queryParams){ return '?' + $.param(queryParams); } // Response -> Promise[Error|JSON] function jsonify(response){ return response .json() .then(function(json){ return json.errors ? Promise.reject(json.errors[0].title) : Promise.resolve(json); }); } return self; }));
public-accountability/littlesis-rails
app/javascript/src/common/api.js
JavaScript
gpl-3.0
3,991
using System; using System.Collections.Generic; using System.Windows; using Newegg.Oversea.Silverlight.Controls; using Newegg.Oversea.Silverlight.ControlPanel.Core.Base; using ECCentral.QueryFilter.MKT; using ECCentral.Portal.UI.MKT.Facades; using ECCentral.Portal.UI.MKT.Models; using ECCentral.Portal.Basic.Utilities; using ECCentral.Portal.Basic; using Newegg.Oversea.Silverlight.Utilities.Validation; using ECCentral.Portal.UI.MKT.Resources; using ECCentral.BizEntity.MKT; using ECCentral.BizEntity.Enum.Resources; namespace ECCentral.Portal.UI.MKT.Views { [View(IsSingleton = true, SingletonType = SingletonTypes.Url)] public partial class SubscriptionMaintain : PageBase { private SubscriptionQueryFilter filter; private SubscriptionQueryFilter filterVM; private SubscriptionQueryFacade facade; private SubscriptionCategoryQueryFacade _facadeCatetory; private SubscriptionQueryVM model; public SubscriptionMaintain() { InitializeComponent(); } public override void OnPageLoad(object sender, EventArgs e) { facade = new SubscriptionQueryFacade(this); _facadeCatetory = new SubscriptionCategoryQueryFacade(this); filter = new SubscriptionQueryFilter(); model = new SubscriptionQueryVM(); model.ChannelID = "1"; model.CompanyCode = Newegg.Oversea.Silverlight.ControlPanel.Core.CPApplication.Current.CompanyCode; QuerySection.DataContext = model; _facadeCatetory.QuerySubscriptionCategory((s, args) => { if (args.FaultsHandle()) return; if (args.Result != null) { var subscriptionCategory = new SubscriptionCategory { SubscriptionCategoryName = ResCommonEnum.Enum_All }; args.Result.Insert(0, subscriptionCategory); } lstSubscriptionCategory.ItemsSource = args.Result; lstSubscriptionCategory.SelectedIndex = 0; }); base.OnPageLoad(sender, e); } private void QueryResultGrid_LoadingDataSource(object sender, Newegg.Oversea.Silverlight.Controls.Data.LoadingDataEventArgs e) { facade.QuerySubscription(QueryResultGrid.QueryCriteria as SubscriptionQueryFilter, e.PageSize, e.PageIndex, e.SortField, (s, args) => { if (args.FaultsHandle()) return; QueryResultGrid.ItemsSource = DynamicConverter<SubscriptionQueryVM>.ConvertToVMList<List<SubscriptionQueryVM>>(args.Result.Rows); QueryResultGrid.TotalCount = args.Result.TotalCount; }); } /// <summary> /// 数据全部导出 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void QueryResultGrid_ExportAllClick(object sender, EventArgs e) { if (filterVM == null || this.QueryResultGrid.TotalCount < 1) { Window.Alert(ResKeywords.Information_ExportFailed); return; } ColumnSet col = new ColumnSet(this.QueryResultGrid); filter = model.ConvertVM<SubscriptionQueryVM, SubscriptionQueryFilter>(); filter.PageInfo = new ECCentral.QueryFilter.Common.PagingInfo() { PageSize = ConstValue.MaxRowCountLimit, PageIndex = 0, SortBy = string.Empty }; facade.ExportExcelFile(filterVM, new ColumnSet[] { col }); } private void Button_Search_Click(object sender, RoutedEventArgs e) { if (ValidationManager.Validate(this.QuerySection)) { filter = model.ConvertVM<SubscriptionQueryVM, SubscriptionQueryFilter>(); if (lstSubscriptionCategory.SelectedValue != null) { filter.SubscriptionCategoryID = Convert.ToInt32(lstSubscriptionCategory.SelectedValue); } filterVM = Newegg.Oversea.Silverlight.Utilities.UtilityHelper.DeepClone<SubscriptionQueryFilter>(filter); QueryResultGrid.QueryCriteria = this.filter; QueryResultGrid.Bind(); } } } }
ZeroOne71/ql
02_ECCentral/02_Portal/UI/ECCentral.Portal.UI.MKT/Views/SubscriptionMaintain.xaml.cs
C#
gpl-3.0
4,382
<?php namespace Anguro\Capse\Models; use Model; use October\Rain\Database\Attach\Resizer; /** * Socio Model */ class Socio extends Model { use \October\Rain\Database\Traits\Validation; /** * @var string The database table used by the model. */ public $table = 'anguro_capse_socios'; /** * @var array Fillable fields */ protected $fillable = ['nombre' , 'url' , 'imagen']; /** * Validation */ public $rules = ['nombre' => 'required|unique:anguro_capse_socios' , 'imagen' => 'required' , 'url' => 'active_url' ]; /** * The attributes on which the post list can be ordered * @var array */ public static $allowedSortingOptions = array( 'nombre asc' => 'Nombre (ascending)', 'nombre desc' => 'Nombre (descending)', 'created_at asc' => 'Created (ascending)', 'created_at desc' => 'Created (descending)', 'updated_at asc' => 'Updated (ascending)', 'updated_at desc' => 'Updated (descending)', 'random' => 'Random' ); /** * @var array Relations */ public $attachOne = [ 'imagen' => ['System\Models\File'] ]; public function beforeSave(){ $img = $this->imagen; if($img){ $resizer = Resizer::open(".".$img->getPath()); $resizer->resize(265, 150, ['mode' => 'auto'])->save(".".$img->getPath(), 100); } } }
4ngelito/plugin-capse
models/Socio.php
PHP
gpl-3.0
1,533
// Decompiled with JetBrains decompiler // Type: System.Data.Common.DbParameter // Assembly: System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // MVID: A0A8E655-5215-4802-816D-C9E5EBD7DA5D // Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.dll using System; using System.ComponentModel; using System.Data; namespace System.Data.Common { /// <summary> /// Represents a parameter to a <see cref="T:System.Data.Common.DbCommand"/> and optionally, its mapping to a <see cref="T:System.Data.DataSet"/> column. For more information on parameters, see Configuring Parameters and Parameter Data Types (ADO.NET). /// </summary> /// <filterpriority>1</filterpriority> public abstract class DbParameter : MarshalByRefObject, IDbDataParameter, IDataParameter { /// <summary> /// Gets or sets the <see cref="T:System.Data.DbType"/> of the parameter. /// </summary> /// /// <returns> /// One of the <see cref="T:System.Data.DbType"/> values. The default is <see cref="F:System.Data.DbType.String"/>. /// </returns> /// <exception cref="T:System.ArgumentException">The property is not set to a valid <see cref="T:System.Data.DbType"/>.</exception><filterpriority>1</filterpriority> [ResDescription("DbParameter_DbType")] [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [RefreshProperties(RefreshProperties.All)] [ResCategory("DataCategory_Data")] public abstract DbType DbType { get; set; } /// <summary> /// Gets or sets a value that indicates whether the parameter is input-only, output-only, bidirectional, or a stored procedure return value parameter. /// </summary> /// /// <returns> /// One of the <see cref="T:System.Data.ParameterDirection"/> values. The default is Input. /// </returns> /// <exception cref="T:System.ArgumentException">The property is not set to one of the valid <see cref="T:System.Data.ParameterDirection"/> values.</exception><filterpriority>1</filterpriority> [ResCategory("DataCategory_Data")] [DefaultValue(ParameterDirection.Input)] [RefreshProperties(RefreshProperties.All)] [ResDescription("DbParameter_Direction")] public abstract ParameterDirection Direction { get; set; } /// <summary> /// Gets or sets a value that indicates whether the parameter accepts null values. /// </summary> /// /// <returns> /// true if null values are accepted; otherwise false. The default is false. /// </returns> /// <filterpriority>1</filterpriority> [EditorBrowsable(EditorBrowsableState.Never)] [Browsable(false)] [DesignOnly(true)] public abstract bool IsNullable { get; set; } /// <summary> /// Gets or sets the name of the <see cref="T:System.Data.Common.DbParameter"/>. /// </summary> /// /// <returns> /// The name of the <see cref="T:System.Data.Common.DbParameter"/>. The default is an empty string (""). /// </returns> /// <filterpriority>1</filterpriority> [DefaultValue("")] [ResCategory("DataCategory_Data")] [ResDescription("DbParameter_ParameterName")] public abstract string ParameterName { get; set; } byte IDbDataParameter.Precision { get { return (byte) 0; } set { } } byte IDbDataParameter.Scale { get { return (byte) 0; } set { } } public virtual byte Precision { get { return ((IDbDataParameter) this).Precision; } set { ((IDbDataParameter) this).Precision = value; } } public virtual byte Scale { get { return ((IDbDataParameter) this).Scale; } set { ((IDbDataParameter) this).Scale = value; } } /// <summary> /// Gets or sets the maximum size, in bytes, of the data within the column. /// </summary> /// /// <returns> /// The maximum size, in bytes, of the data within the column. The default value is inferred from the parameter value. /// </returns> /// <filterpriority>1</filterpriority> [ResDescription("DbParameter_Size")] [ResCategory("DataCategory_Data")] public abstract int Size { get; set; } /// <summary> /// Gets or sets the name of the source column mapped to the <see cref="T:System.Data.DataSet"/> and used for loading or returning the <see cref="P:System.Data.Common.DbParameter.Value"/>. /// </summary> /// /// <returns> /// The name of the source column mapped to the <see cref="T:System.Data.DataSet"/>. The default is an empty string. /// </returns> /// <filterpriority>1</filterpriority> [DefaultValue("")] [ResCategory("DataCategory_Update")] [ResDescription("DbParameter_SourceColumn")] public abstract string SourceColumn { get; set; } /// <summary> /// Sets or gets a value which indicates whether the source column is nullable. This allows <see cref="T:System.Data.Common.DbCommandBuilder"/> to correctly generate Update statements for nullable columns. /// </summary> /// /// <returns> /// true if the source column is nullable; false if it is not. /// </returns> /// <filterpriority>1</filterpriority> [ResCategory("DataCategory_Update")] [DefaultValue(false)] [RefreshProperties(RefreshProperties.All)] [ResDescription("DbParameter_SourceColumnNullMapping")] [EditorBrowsable(EditorBrowsableState.Advanced)] public abstract bool SourceColumnNullMapping { get; set; } /// <summary> /// Gets or sets the <see cref="T:System.Data.DataRowVersion"/> to use when you load <see cref="P:System.Data.Common.DbParameter.Value"/>. /// </summary> /// /// <returns> /// One of the <see cref="T:System.Data.DataRowVersion"/> values. The default is Current. /// </returns> /// <exception cref="T:System.ArgumentException">The property is not set to one of the <see cref="T:System.Data.DataRowVersion"/> values.</exception><filterpriority>1</filterpriority> [ResCategory("DataCategory_Update")] [ResDescription("DbParameter_SourceVersion")] [DefaultValue(DataRowVersion.Current)] public virtual DataRowVersion SourceVersion { get { return DataRowVersion.Default; } set { } } /// <summary> /// Gets or sets the value of the parameter. /// </summary> /// /// <returns> /// An <see cref="T:System.Object"/> that is the value of the parameter. The default value is null. /// </returns> /// <filterpriority>1</filterpriority> [ResCategory("DataCategory_Data")] [ResDescription("DbParameter_Value")] [RefreshProperties(RefreshProperties.All)] [DefaultValue(null)] public abstract object Value { get; set; } /// <summary> /// Resets the DbType property to its original settings. /// </summary> /// <filterpriority>2</filterpriority> [EditorBrowsable(EditorBrowsableState.Advanced)] public abstract void ResetDbType(); } }
mater06/LEGOChimaOnlineReloaded
LoCO Client Files/Decompressed Client/Extracted DLL/System.Data/System/Data/Common/DbParameter.cs
C#
gpl-3.0
7,169
<?php namespace EcommerceBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; use Symfony\Component\Validator\Constraints as Assert; use CoreBundle\Entity\Timestampable; use CoreBundle\Entity\Image; /** * AttributeValue Entity class * * @ORM\Table(name="attribute_value") * @ORM\Entity(repositoryClass="EcommerceBundle\Entity\Repository\AttributeValueRepository") */ class AttributeValue extends Timestampable { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="name", type="string", length=255) * @Assert\NotBlank */ private $name; /** * @var Attribute * * @ORM\ManyToOne(targetEntity="Attribute", inversedBy="values", fetch="EAGER") * @ORM\JoinColumn(name="attribute_id", referencedColumnName="id", nullable=false) * @Assert\NotBlank */ private $attribute; /** * @var Image * * @ORM\OneToOne(targetEntity="CoreBundle\Entity\Image", cascade={"persist", "remove"}, fetch="EAGER") */ private $image; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Get name * * @return string */ public function getName() { return $this->name; } /** * Set name * * @param string $name * * @return AttributeValue */ public function setName($name) { $this->name = $name; return $this; } /** * Set attribute * * @param Attribute $attribute * * @return AttributeValue */ public function setAttribute(Attribute $attribute = null) { $this->attribute = $attribute; return $this; } /** * Get attribute * * @return Attribute */ public function getAttribute() { return $this->attribute; } /** * Set image * * @param Image $image * * @return AttributeValue */ public function setImage(Image $image = null) { $this->image = $image; return $this; } /** * Get image * * @return Image */ public function getImage() { return $this->image; } /** * @return string */ public function __toString() { return $this->attribute->getName().': '.$this->name; } }
sebardo/ecommerce
EcommerceBundle/Entity/AttributeValue.php
PHP
gpl-3.0
2,565
#include "voro++_2d.hh" using namespace voro; // This function returns a random floating point number between 0 and 1 double rnd() {return double(rand())/RAND_MAX;} int main() { double x,y; voronoicell_nonconvex_2d v; // Initialize the Voronoi cell to be a cube of side length 2, centered // on the origin v.init_nonconvex(-1,0.8,-1,0.4,4,5,5,4); v.draw_gnuplot(0,0,"nonconvex_cell.gnu"); v.plane(0.3,0); v.plane(0.4,0); // Cut the cell by 100 random planes which are all a distance 1 away // from the origin, to make an approximation to a sphere /*for(int i=0;i<100;i++) { x=2*rnd()-1; y=2*rnd()-1; rsq=x*x+y*y; if(rsq>0.01&&rsq<1) { r=1/sqrt(rsq);x*=r;y*=r; v.plane(x,y,1); } }*/ // Print out several statistics about the computed cell v.centroid(x,y); printf("Perimeter is %g\n" "Area is %g\n" "Centroid is (%g,%g)\n",v.perimeter(),v.area(),x,y); // Output the Voronoi cell to a file, in the gnuplot format v.draw_gnuplot(0,0,"nonconvex_cell2.gnu"); }
LarsHadidi/BDSim
Voro++2D/examples/boundary/nonconvex_cell.cc
C++
gpl-3.0
1,017
#include <iostream> #include "tl_dense_vector_impl_eigen.h" #ifdef HAVE_VIENNACL #define VIENNACL_HAVE_EIGEN #include <viennacl/vector.hpp> #include "tl_dense_vector_impl_viennacl.h" #endif // HAVE_VIENNACL // --------------------------------------------------------------------------- // constructor & destructor // --------------------------------------------------------------------------- TlDenseVector_ImplEigen::TlDenseVector_ImplEigen( TlDenseVectorObject::index_type dim) : vector_(VectorDataType::Zero(dim)) {} TlDenseVector_ImplEigen::TlDenseVector_ImplEigen( const TlDenseVector_ImplEigen& rhs) { this->vector_ = rhs.vector_; } TlDenseVector_ImplEigen::TlDenseVector_ImplEigen(const std::vector<double>& rhs) : vector_(MapTypeConst(rhs.data(), rhs.size())) {} TlDenseVector_ImplEigen::TlDenseVector_ImplEigen( const double* p, const TlDenseVectorObject::size_type size) : vector_(MapTypeConst(p, size)) {} TlDenseVector_ImplEigen::TlDenseVector_ImplEigen(const VectorDataType& rhs) { this->vector_ = rhs; } #ifdef HAVE_VIENNACL TlDenseVector_ImplEigen::TlDenseVector_ImplEigen( const TlDenseVector_ImplViennaCL& rhs) : vector_(VectorDataType::Zero(rhs.getSize())) { viennacl::copy(rhs.vector_, this->vector_); } #endif // HAVE_VIENNACL TlDenseVector_ImplEigen::operator std::vector<double>() const { const std::size_t size = this->getSize(); std::vector<double> answer(size); MapType(&(answer[0]), size) = this->vector_; return answer; } TlDenseVector_ImplEigen::~TlDenseVector_ImplEigen() {} // --------------------------------------------------------------------------- // properties // --------------------------------------------------------------------------- TlDenseVectorObject::size_type TlDenseVector_ImplEigen::getSize() const { return this->vector_.rows(); } void TlDenseVector_ImplEigen::resize( const TlDenseVectorObject::index_type newSize) { this->vector_.conservativeResizeLike(VectorDataType::Zero(newSize, 1)); } double TlDenseVector_ImplEigen::get( const TlDenseVectorObject::index_type i) const { return this->vector_.coeff(i); } void TlDenseVector_ImplEigen::set(const TlDenseVectorObject::index_type i, const double value) { this->vector_.coeffRef(i) = value; } void TlDenseVector_ImplEigen::add(const TlDenseVectorObject::index_type i, const double value) { this->vector_.coeffRef(i) += value; } void TlDenseVector_ImplEigen::mul(const TlDenseVectorObject::index_type i, const double value) { this->vector_.coeffRef(i) *= value; } // --------------------------------------------------------------------------- // operators // --------------------------------------------------------------------------- TlDenseVector_ImplEigen& TlDenseVector_ImplEigen::operator=( const TlDenseVector_ImplEigen& rhs) { if (this != &rhs) { this->vector_ = rhs.vector_; } return (*this); } TlDenseVector_ImplEigen& TlDenseVector_ImplEigen::operator+=( const TlDenseVector_ImplEigen& rhs) { this->vector_ += rhs.vector_; return *this; } TlDenseVector_ImplEigen& TlDenseVector_ImplEigen::operator-=( const TlDenseVector_ImplEigen& rhs) { this->vector_ -= rhs.vector_; return *this; } TlDenseVector_ImplEigen& TlDenseVector_ImplEigen::operator*=(const double rhs) { this->vector_ *= rhs; return *this; } TlDenseVector_ImplEigen& TlDenseVector_ImplEigen::operator/=(const double rhs) { return this->operator*=(1.0 / rhs); } double TlDenseVector_ImplEigen::operator*( const TlDenseVector_ImplEigen& rhs) const { return this->dot(rhs); } // --------------------------------------------------------------------------- // operations // --------------------------------------------------------------------------- double TlDenseVector_ImplEigen::sum() const { return this->vector_.array().sum(); } void TlDenseVector_ImplEigen::sortByGreater() { std::sort(this->vector_.data(), this->vector_.data() + this->getSize(), std::greater<double>()); } double TlDenseVector_ImplEigen::dot(const TlDenseVector_ImplEigen& rhs) const { assert(this->getSize() == rhs.getSize()); const double answer = this->vector_.dot(rhs.vector_); return answer; } TlDenseVector_ImplEigen& TlDenseVector_ImplEigen::dotInPlace( const TlDenseVector_ImplEigen& rhs) { assert(this->getSize() == rhs.getSize()); this->vector_.array() *= rhs.vector_.array(); return *this; } // --------------------------------------------------------------------------- // others // --------------------------------------------------------------------------- TlDenseVector_ImplEigen operator+(const TlDenseVector_ImplEigen& rhs1, const TlDenseVector_ImplEigen& rhs2) { TlDenseVector_ImplEigen answer = rhs1; answer += rhs2; return answer; } TlDenseVector_ImplEigen operator-(const TlDenseVector_ImplEigen& rhs1, const TlDenseVector_ImplEigen& rhs2) { TlDenseVector_ImplEigen answer = rhs1; answer -= rhs2; return answer; } TlDenseVector_ImplEigen operator*(const TlDenseVector_ImplEigen& rhs1, const double rhs2) { TlDenseVector_ImplEigen answer = rhs1; answer *= rhs2; return answer; } TlDenseVector_ImplEigen operator*(const double rhs1, const TlDenseVector_ImplEigen& rhs2) { return (rhs2 * rhs1); }
ProteinDF/ProteinDF
src/libpdftl/tl_dense_vector_impl_eigen.cc
C++
gpl-3.0
5,589
import VK from 'VK'; import { VK_API_VERSION } from '../constants'; /** * Fetch friends. * @param {Object} options * @return {Promise<Object>} */ export function fetchFriends(options = {}) { const mergedOptions = { ...options, order: 'hints', fields: 'photo_100', v: VK_API_VERSION, }; return new Promise((resolve, reject) => { VK.api('friends.get', mergedOptions, response => { if (response.response) resolve(response.response); else reject(response.error); }); }); }
AlexeySmolyakov/likeometer-redux
src/api/friends.js
JavaScript
gpl-3.0
519
/* * Copyright (C) 2019 Miky Mikusher * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. */ package cv.designpatterns.factory; /** * @author Miky Mikusher * */ public abstract class AbstractFactory { abstract Color getColor(String color); abstract Shape getShape(String shape); }
mikusher/JavaBasico
src/cv/designpatterns/factory/AbstractFactory.java
Java
gpl-3.0
544
/* This file is part of perfusionkit. Copyright 2010 Henning Meyer perfusionkit is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. perfusionkit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with perfusionkit. If not, see <http://www.gnu.org/licenses/>. */ #include "ctimagetreemodel_serializer.h" #include <fstream> #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_iarchive.hpp> #include <boost/iostreams/filtering_stream.hpp> #include <boost/iostreams/filter/zlib.hpp> #include "ctimagetreemodel.h" #include "ctimagetreeitem.h" #include "binaryimagetreeitem.h" #include "serialization_helper.h" //#include <boost/serialization/export.hpp> //BOOST_CLASS_EXPORT_GUID(CTImageTreeItem, "CTImageTreeItem"); //BOOST_CLASS_EXPORT_GUID(BinaryImageTreeItem, "BinaryImageTreeItem"); void deserializeCTImageTreeModelFromFile(CTImageTreeModel &model, const std::string &fname) { using namespace std; using namespace boost::iostreams; std::ifstream inFileStream( fname.c_str(), ios_base::in | ios_base::binary ); filtering_stream<input> inStreamFilter; inStreamFilter.push(zlib_decompressor()); inStreamFilter.push(inFileStream); boost::archive::binary_iarchive ia( inStreamFilter ); model.setSerializationPath( fname ); ia >> model; } void serializeCTImageTreeModelToFile(CTImageTreeModel &model, const std::string &fname) { using namespace std; using namespace boost::iostreams; ofstream outFileStream( fname.c_str(), ios_base::out | ios_base::binary ); filtering_stream<output> outStreamFilter; outStreamFilter.push(zlib_compressor()); outStreamFilter.push(outFileStream); boost::archive::binary_oarchive oa( outStreamFilter ); model.setSerializationPath( fname ); oa << model; }
hmeyer/perfusionkit
serialization/ctimagetreemodel_serializer.cpp
C++
gpl-3.0
2,221
<?php /** * PHPUnit * * Copyright (c) 2002-2007, Sebastian Bergmann <sb@sebastian-bergmann.de>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @category Testing * @package PHPUnit * @author Jan Borsodi <jb@ez.no> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2007 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version SVN: $Id: Stub.php 537 2007-02-24 06:58:18Z sb $ * @link http://www.phpunit.de/ * @since File available since Release 3.0.0 */ require_once 'PHPUnit/Util/Filter.php'; require_once 'PHPUnit/Framework/MockObject/Builder/Identity.php'; PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); /** * Builder interface for stubs which are actions replacing an invocation. * * @category Testing * @package PHPUnit * @author Jan Borsodi <jb@ez.no> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2007 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 3.2.5 * @link http://www.phpunit.de/ * @since Interface available since Release 3.0.0 */ interface PHPUnit_Framework_MockObject_Builder_Stub extends PHPUnit_Framework_MockObject_Builder_Identity { /** * Stubs the matching method with the stub object $stub. Any invocations of * the matched method will now be handled by the stub instead. * * @param PHPUnit_Framework_MockObject_Stub $stub The stub object. * @return PHPUnit_Framework_MockObject_Builder_Identity */ public function will(PHPUnit_Framework_MockObject_Stub $stub); } ?>
csinitiative/qframe
library/PHPUnit/Framework/MockObject/Builder/Stub.php
PHP
gpl-3.0
3,265
""" This module provides functions that generate commonly used Hamiltonian terms. """ __all__ = [ "Annihilator", "Creator", "CPFactory", "HoppingFactory", "PairingFactory", "HubbardFactory", "CoulombFactory", "HeisenbergFactory", "IsingFactory", "TwoSpinTermFactory", ] from HamiltonianPy.quantumoperator.constant import ANNIHILATION, CREATION, \ SPIN_DOWN, SPIN_UP from HamiltonianPy.quantumoperator.particlesystem import AoC, ParticleTerm from HamiltonianPy.quantumoperator.spinsystem import * def Creator(site, spin=0, orbit=0): """ Generate creation operator: $c_i^{\\dagger}$. Parameters ---------- site : list, tuple or 1D np.ndarray The coordinates of the localized single-particle state. The `site` parameter should be 1D array with length 1,2 or 3. spin : int, optional The spin index of the single-particle state. Default: 0. orbit : int, optional The orbit index of the single-particle state. Default: 0. Returns ------- operator : AoC The corresponding creation operator. Examples -------- >>> from HamiltonianPy.quantumoperator import Creator >>> Creator((0, 0), spin=1) AoC(otype=CREATION, site=(0, 0), spin=1, orbit=0) """ return AoC(CREATION, site=site, spin=spin, orbit=orbit) def Annihilator(site, spin=0, orbit=0): """ Generate annihilation operator: $c_i$. Parameters ---------- site : list, tuple or 1D np.ndarray The coordinates of the localized single-particle state. The `site` parameter should be 1D array with length 1,2 or 3. spin : int, optional The spin index of the single-particle state. Default: 0. orbit : int, optional The orbit index of the single-particle state. Default: 0. Returns ------- operator : AoC The corresponding annihilation operator. Examples -------- >>> from HamiltonianPy.quantumoperator import Annihilator >>> Annihilator((0, 0), spin=0) AoC(otype=ANNIHILATION, site=(0, 0), spin=0, orbit=0) """ return AoC(ANNIHILATION, site=site, spin=spin, orbit=orbit) def CPFactory(site, *, spin=0, orbit=0, coeff=1.0): """ Generate chemical potential term: '$\\mu c_i^{\\dagger} c_i$'. Parameters ---------- site : list, tuple or 1D np.ndarray The coordinates of the localized single-particle state. The `site` parameter should be 1D array with length 1,2 or 3. spin : int, optional, keyword-only The spin index of the single-particle state. Default: 0. orbit : int, optional, keyword-only The orbit index of the single-particle state. Default: 0. coeff : int or float, optional, keyword-only The coefficient of this term. Default: 1.0. Returns ------- term : ParticleTerm The corresponding chemical potential term. Examples -------- >>> from HamiltonianPy.quantumoperator import CPFactory >>> term = CPFactory((0, 0)) >>> print(term) The coefficient of this term: 1.0 The component operators: AoC(otype=CREATION, site=(0, 0), spin=0, orbit=0) AoC(otype=ANNIHILATION, site=(0, 0), spin=0, orbit=0) """ c = AoC(CREATION, site=site, spin=spin, orbit=orbit) a = AoC(ANNIHILATION, site=site, spin=spin, orbit=orbit) return ParticleTerm((c, a), coeff=coeff, classification="number") def HoppingFactory( site0, site1, *, spin0=0, spin1=None, orbit0=0, orbit1=None, coeff=1.0 ): """ Generate hopping term: '$t c_i^{\\dagger} c_j$'. These parameters suffixed with '0' are for the creation operator and '1' for annihilation operator. Parameters ---------- site0, site1 : list, tuple or 1D np.ndarray The coordinates of the localized single-particle state. `site0` and `site1` should be 1D array with length 1, 2 or 3. spin0, spin1 : int, optional, keyword-only The spin index of the single-particle state. The default value for `spin0` is 0; The default value for `spin1` is None, which implies that `spin1` takes the same value as `spin0`. orbit0, orbit1 : int, optional, keyword-only The orbit index of the single-particle state. The default value for `orbit0` is 0; The default value for `orbit1` is None, which implies that `orbit1` takes the same value as `orbit0`. coeff : int, float or complex, optional, keyword-only The coefficient of this term. Default: 1.0. Returns ------- term : ParticleTerm The corresponding hopping term. Examples -------- >>> from HamiltonianPy.quantumoperator import HoppingFactory >>> term = HoppingFactory(site0=(0, 0), site1=(1, 1), spin0=1) >>> print(term) The coefficient of this term: 1.0 The component operators: AoC(otype=CREATION, site=(0, 0), spin=1, orbit=0) AoC(otype=ANNIHILATION, site=(1, 1), spin=1, orbit=0) >>> term = HoppingFactory(site0=(0, 0), site1=(1, 1), spin0=0, spin1=1) >>> print(term) The coefficient of this term: 1.0 The component operators: AoC(otype=CREATION, site=(0, 0), spin=0, orbit=0) AoC(otype=ANNIHILATION, site=(1, 1), spin=1, orbit=0) """ if spin1 is None: spin1 = spin0 if orbit1 is None: orbit1 = orbit0 c = AoC(CREATION, site=site0, spin=spin0, orbit=orbit0) a = AoC(ANNIHILATION, site=site1, spin=spin1, orbit=orbit1) classification = "hopping" if c.state != a.state else "number" return ParticleTerm((c, a), coeff=coeff, classification=classification) def PairingFactory( site0, site1, *, spin0=0, spin1=0, orbit0=0, orbit1=0, coeff=1.0, which="h" ): """ Generate pairing term: '$p c_i^{\\dagger} c_j^{\\dagger}$' or '$p c_i c_j$'. These parameters suffixed with '0' are for the 1st operator and '1' for 2nd operator. Parameters ---------- site0, site1 : list, tuple or 1D np.ndarray The coordinates of the localized single-particle state. `site0` and `site1` should be 1D array with length 1, 2 or 3. spin0, spin1 : int, optional, keyword-only The spin index of the single-particle state. Default: 0. orbit0, orbit1 : int, optional, keyword-only The orbit index of the single-particle state. Default: 0. coeff : int, float or complex, optional, keyword-only The coefficient of this term. Default: 1.0. which : str, optional, keyword-only Determine whether to generate a particle- or hole-pairing term. Valid values: ["h" | "hole"] for hole-pairing; ["p" | "particle"] for particle-pairing. Default: "h". Returns ------- term : ParticleTerm The corresponding pairing term. Examples -------- >>> from HamiltonianPy.quantumoperator import PairingFactory >>> term = PairingFactory((0, 0), (1, 1), spin0=0, spin1=1, which="h") >>> print(term) The coefficient of this term: 1.0 The component operators: AoC(otype=ANNIHILATION, site=(0, 0), spin=0, orbit=0) AoC(otype=ANNIHILATION, site=(1, 1), spin=1, orbit=0) >>> term = PairingFactory((0, 0), (1, 1), spin0=0, spin1=1, which="p") >>> print(term) The coefficient of this term: 1.0 The component operators: AoC(otype=CREATION, site=(0, 0), spin=0, orbit=0) AoC(otype=CREATION, site=(1, 1), spin=1, orbit=0) """ assert which in ("h", "hole", "p", "particle") otype = ANNIHILATION if which in ("h", "hole") else CREATION aoc0 = AoC(otype, site=site0, spin=spin0, orbit=orbit0) aoc1 = AoC(otype, site=site1, spin=spin1, orbit=orbit1) return ParticleTerm((aoc0, aoc1), coeff=coeff) def HubbardFactory(site, *, orbit=0, coeff=1.0): """ Generate Hubbard term: '$U n_{i\\uparrow} n_{i\\downarrow}$'. This function is valid only for spin-1/2 system. Parameters ---------- site : list, tuple or 1D np.ndarray The coordinates of the localized single-particle state. `site` should be 1D array with length 1,2 or 3. orbit : int, optional, keyword-only The orbit index of the single-particle state. Default: 0. coeff : int or float, optional, keyword-only The coefficient of this term. Default: 1.0. Returns ------- term : ParticleTerm The corresponding Hubbard term. Examples -------- >>> from HamiltonianPy.quantumoperator import HubbardFactory >>> term = HubbardFactory(site=(0, 0)) >>> print(term) The coefficient of this term: 1.0 The component operators: AoC(otype=CREATION, site=(0, 0), spin=1, orbit=0) AoC(otype=ANNIHILATION, site=(0, 0), spin=1, orbit=0) AoC(otype=CREATION, site=(0, 0), spin=0, orbit=0) AoC(otype=ANNIHILATION, site=(0, 0), spin=0, orbit=0) """ c_up = AoC(CREATION, site=site, spin=SPIN_UP, orbit=orbit) c_down = AoC(CREATION, site=site, spin=SPIN_DOWN, orbit=orbit) a_up = AoC(ANNIHILATION, site=site, spin=SPIN_UP, orbit=orbit) a_down = AoC(ANNIHILATION, site=site, spin=SPIN_DOWN, orbit=orbit) return ParticleTerm( (c_up, a_up, c_down, a_down), coeff=coeff, classification="Coulomb" ) def CoulombFactory( site0, site1, *, spin0=0, spin1=0, orbit0=0, orbit1=0, coeff=1.0 ): """ Generate Coulomb interaction term: '$U n_i n_j$'. These parameters suffixed with '0' are for the 1st operator and '1' for 2nd operator. Parameters ---------- site0, site1 : list, tuple or 1D np.ndarray The coordinates of the localized single-particle state. `site0` and `site1` should be 1D array with length 1, 2 or 3. spin0, spin1 : int, optional, keyword-only The spin index of the single-particle state. Default: 0. orbit0, orbit1 : int, optional, keyword-only The orbit index of the single-particle state. Default: 0. coeff : int or float, optional, keyword-only The coefficient of this term. Default: 1.0. Returns ------- term : ParticleTerm The corresponding Coulomb interaction term. Examples -------- >>> from HamiltonianPy.quantumoperator import CoulombFactory >>> term = CoulombFactory((0, 0), (1, 1), spin0=0, spin1=1) >>> print(term) The coefficient of this term: 1.0 The component operators: AoC(otype=CREATION, site=(0, 0), spin=0, orbit=0) AoC(otype=ANNIHILATION, site=(0, 0), spin=0, orbit=0) AoC(otype=CREATION, site=(1, 1), spin=1, orbit=0) AoC(otype=ANNIHILATION, site=(1, 1), spin=1, orbit=0) """ c0 = AoC(CREATION, site=site0, spin=spin0, orbit=orbit0) a0 = AoC(ANNIHILATION, site=site0, spin=spin0, orbit=orbit0) c1 = AoC(CREATION, site=site1, spin=spin1, orbit=orbit1) a1 = AoC(ANNIHILATION, site=site1, spin=spin1, orbit=orbit1) return ParticleTerm((c0, a0, c1, a1), coeff=coeff, classification="Coulomb") def HeisenbergFactory(site0, site1, *, coeff=1.0): """ Generate Heisenberg interaction term: '$J S_i S_j$'. Parameters ---------- site0, site1 : list, tuple or 1D np.ndarray The coordinates of the lattice site on which the spin operator is defined. `site0` and `site1` should be 1D array with length 1, 2 or 3. `site0` for the first spin operator and `site1` for the second spin operator. coeff : int or float, optional, keyword-only The coefficient of this term. Default: 1.0. Returns ------- terms : 3-tuple terms[0] is the '$J S_i^z S_j^z$' term; terms[1] is the '$J/2 S_i^+ S_j^-$' term; terms[2] is the '$J/2 S_i^- S_j^+$' term. Examples -------- >>> from HamiltonianPy.quantumoperator import HeisenbergFactory >>> term = HeisenbergFactory((0, 0), (1, 1)) >>> print(term[0]) The coefficient of this term: 1.0 The component operators: SpinOperator(otype="z", site=(0, 0)) SpinOperator(otype="z", site=(1, 1)) >>> print(term[1]) The coefficient of this term: 0.5 The component operators: SpinOperator(otype="p", site=(0, 0)) SpinOperator(otype="m", site=(1, 1)) >>> print(term[2]) The coefficient of this term: 0.5 The component operators: SpinOperator(otype="m", site=(0, 0)) SpinOperator(otype="p", site=(1, 1)) """ sz0 = SpinOperator(otype="z", site=site0) sp0 = SpinOperator(otype="p", site=site0) sm0 = SpinOperator(otype="m", site=site0) sz1 = SpinOperator(otype="z", site=site1) sp1 = SpinOperator(otype="p", site=site1) sm1 = SpinOperator(otype="m", site=site1) return ( SpinInteraction((sz0, sz1), coeff=coeff), SpinInteraction((sp0, sm1), coeff=coeff/2), SpinInteraction((sm0, sp1), coeff=coeff/2), ) def IsingFactory(site0, site1, alpha, *, coeff=1.0): """ Generate Ising type spin interaction term: '$J S_i^{\\alpha} S_j^{\\alpha}$' Parameters ---------- site0, site1 : list, tuple or 1D np.ndarray The coordinates of the lattice site on which the spin operator is defined. `site0` and `site1` should be 1D array with length 1, 2 or 3. `site0` for the first spin operator and `site1` for the second spin operator. alpha : {"x", "y" or "z"} Which type of spin operator is involved. coeff : int or float, optional, keyword-only The coefficient of this term. Default: 1.0. Returns ------- term: SpinInteraction The corresponding spin interaction term. Examples -------- >>> from HamiltonianPy.quantumoperator import IsingFactory >>> term = IsingFactory((0, 0), (1, 1), "x") >>> print(term) The coefficient of this term: 1.0 The component operators: SpinOperator(otype="x", site=(0, 0)) SpinOperator(otype="x", site=(1, 1)) """ assert alpha in ("x", "y", "z") s0_alpha = SpinOperator(otype=alpha, site=site0) s1_alpha = SpinOperator(otype=alpha, site=site1) return SpinInteraction((s0_alpha, s1_alpha), coeff=coeff) def TwoSpinTermFactory(site0, site1, alpha0, alpha1, *, coeff=1.0): """ Generate general two spin interaction term: '$J S_i^{\\alpha} S_j^{\\beta}$' Parameters ---------- site0, site1 : list, tuple or 1D np.ndarray The coordinates of the lattice site on which the spin operator is defined. `site0` and `site1` should be 1D array with length 1, 2 or 3. `site0` for the first spin operator and `site1` for the second spin operator. alpha0, alpha1 : {"x", "y" or "z"} Which type of spin operator is involved. `alpha0` for the first and `alpha1` for the second spin operator. coeff : int or float, optional, keyword-only The coefficient of this term. Default: 1.0. Returns ------- term: SpinInteraction The corresponding spin interaction term. Examples -------- >>> from HamiltonianPy.quantumoperator import TwoSpinTermFactory >>> term = TwoSpinTermFactory((0, 0), (1, 1), alpha0="x", alpha1="y") >>> print(term) The coefficient of this term: 1.0 The component operators: SpinOperator(otype="x", site=(0, 0)) SpinOperator(otype="y", site=(1, 1)) """ assert alpha0 in ("x", "y", "z") assert alpha1 in ("x", "y", "z") s0_alpha = SpinOperator(otype=alpha0, site=site0) s1_alpha = SpinOperator(otype=alpha1, site=site1) return SpinInteraction((s0_alpha, s1_alpha), coeff=coeff)
wangshiphys/HamiltonianPy
HamiltonianPy/quantumoperator/factory.py
Python
gpl-3.0
15,843